mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-10-21 13:34:04 +02:00
[#5793] added subscriptions.Broker.TotalClients() method
This commit is contained in:
1 parent
f9a2d6c6ae
commit
755149c915
3 files changed
+22
No files matched your search
@@ -30,6 +30,11 @@ func (b *Broker) ChunkedClients(chunkSize int) [][]Client {
|
||||
return list.ToChunks(b.store.Values(), chunkSize)
|
||||
}
|
||||
|
||||
// TotalClients returns the total number of registered clients.
|
||||
func (b *Broker) TotalClients() int {
|
||||
return b.store.Length()
|
||||
}
|
||||
|
||||
// ClientById finds a registered client by its id.
|
||||
//
|
||||
// Returns non-nil error when client with clientId is not registered.
|
||||
|
||||
@@ -62,6 +62,21 @@ func TestChunkedClients(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTotalClients(t *testing.T) {
|
||||
b := subscriptions.NewBroker()
|
||||
|
||||
if total := b.TotalClients(); total != 0 {
|
||||
t.Fatalf("Expected no clients, got %d", total)
|
||||
}
|
||||
|
||||
b.Register(subscriptions.NewDefaultClient())
|
||||
b.Register(subscriptions.NewDefaultClient())
|
||||
|
||||
if total := b.TotalClients(); total != 2 {
|
||||
t.Fatalf("Expected %d clients, got %d", 2, total)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientById(t *testing.T) {
|
||||
b := subscriptions.NewBroker()
|
||||
|
||||
|
||||
Reference in new issue
Block a user