MVP 1.0: IRC-over-HTTP chat server #10
@@ -13,7 +13,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/chat/internal/broker"
|
|
||||||
"git.eeqj.de/sneak/chat/internal/config"
|
"git.eeqj.de/sneak/chat/internal/config"
|
||||||
"git.eeqj.de/sneak/chat/internal/db"
|
"git.eeqj.de/sneak/chat/internal/db"
|
||||||
"git.eeqj.de/sneak/chat/internal/globals"
|
"git.eeqj.de/sneak/chat/internal/globals"
|
||||||
@@ -855,42 +854,4 @@ func TestNickBroadcastToChannels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broker unit tests
|
// Broker tests are in internal/broker/broker_test.go
|
||||||
|
|
||||||
func TestBrokerNotifyWithoutWaiters(t *testing.T) {
|
|
||||||
b := broker.New()
|
|
||||||
// Should not panic
|
|
||||||
b.Notify(999)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBrokerWaitAndNotify(t *testing.T) {
|
|
||||||
b := broker.New()
|
|
||||||
ch := b.Wait(1)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
b.Notify(1)
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
// ok
|
|
||||||
case <-time.After(2 * time.Second):
|
|
||||||
t.Fatal("timeout waiting for notification")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBrokerRemove(t *testing.T) {
|
|
||||||
b := broker.New()
|
|
||||||
ch := b.Wait(1)
|
|
||||||
b.Remove(1, ch)
|
|
||||||
// Notify should not send to removed channel
|
|
||||||
b.Notify(1)
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
t.Fatal("should not receive after remove")
|
|
||||||
case <-time.After(100 * time.Millisecond):
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user