mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-29 21:31:07 +02:00
New Streams and Quality structures
This commit is contained in:
52
messaging/streams_test.go
Normal file
52
messaging/streams_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package messaging
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWithOneStream(t *testing.T) {
|
||||
streams := New()
|
||||
|
||||
// Subscribe to new streams
|
||||
event := make(chan string, 8)
|
||||
streams.Subscribe(event)
|
||||
|
||||
// Create a stream
|
||||
stream, err := streams.Create("demo")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create stream")
|
||||
}
|
||||
|
||||
// Check that we receive the creation event
|
||||
e := <-event
|
||||
if e != "demo" {
|
||||
t.Errorf("Message has wrong content: %s != demo", e)
|
||||
}
|
||||
|
||||
// Create a quality
|
||||
quality := stream.CreateQuality("source")
|
||||
|
||||
// Register one output
|
||||
output := make(chan []byte, 64)
|
||||
quality.Register(output)
|
||||
stream.IncrementClientCount()
|
||||
|
||||
// Try to pass one message
|
||||
quality.Broadcast <- []byte("hello world")
|
||||
msg := <-output
|
||||
if string(msg) != "hello world" {
|
||||
t.Errorf("Message has wrong content: %s != hello world", msg)
|
||||
}
|
||||
|
||||
// Check client count
|
||||
if count := stream.ClientCount(); count != 1 {
|
||||
t.Errorf("Client counter returned %d, expected 1", count)
|
||||
}
|
||||
|
||||
// Unregister
|
||||
quality.Unregister(output)
|
||||
stream.DecrementClientCount()
|
||||
|
||||
// Check client count
|
||||
if count := stream.ClientCount(); count != 0 {
|
||||
t.Errorf("Client counter returned %d, expected 0", count)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user