updated hws.ThrowError to not return an error and log it to console instead
fixed errors_test fixed tests
This commit is contained in:
@@ -15,8 +15,9 @@ func newTestServerWithNotifier(t *testing.T) *Server {
|
||||
t.Helper()
|
||||
|
||||
cfg := &Config{
|
||||
Host: "127.0.0.1",
|
||||
Port: 0,
|
||||
Host: "127.0.0.1",
|
||||
Port: 0,
|
||||
ShutdownDelay: 0, // No delay for tests
|
||||
}
|
||||
|
||||
server, err := NewServer(cfg)
|
||||
@@ -359,7 +360,7 @@ func Test_ActiveClientStaysAlive(t *testing.T) {
|
||||
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
<-ticker.C
|
||||
server.NotifySub(notify.Notification{
|
||||
Target: client.sub.ID,
|
||||
@@ -460,7 +461,7 @@ func Test_SlowConsumerTolerance(t *testing.T) {
|
||||
defer close(stop)
|
||||
|
||||
// Send 10 notifications quickly (buffer is 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
server.NotifySub(notify.Notification{
|
||||
Target: client.sub.ID,
|
||||
Message: "Burst message",
|
||||
@@ -468,7 +469,7 @@ func Test_SlowConsumerTolerance(t *testing.T) {
|
||||
}
|
||||
|
||||
// Client should receive all 10
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
select {
|
||||
case <-notifications:
|
||||
// Received
|
||||
@@ -487,7 +488,7 @@ func Test_SingleTimeoutRecovery(t *testing.T) {
|
||||
defer close(stop)
|
||||
|
||||
// Fill buffer completely (buffer is 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
server.NotifySub(notify.Notification{
|
||||
Target: client.sub.ID,
|
||||
Message: "Fill buffer",
|
||||
@@ -500,15 +501,15 @@ func Test_SingleTimeoutRecovery(t *testing.T) {
|
||||
Message: "Timeout message",
|
||||
})
|
||||
|
||||
// Wait for timeout
|
||||
time.Sleep(6 * time.Second)
|
||||
// Wait for timeout (5s timeout + small buffer)
|
||||
time.Sleep(5100 * time.Millisecond)
|
||||
|
||||
// Check failure count (should be 1)
|
||||
fails := atomic.LoadInt32(&client.consecutiveFails)
|
||||
require.Equal(t, int32(1), fails, "Should have 1 timeout")
|
||||
|
||||
// Now read all buffered messages
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
<-notifications
|
||||
}
|
||||
|
||||
@@ -538,7 +539,7 @@ func Test_ConsecutiveFailureDisconnect(t *testing.T) {
|
||||
defer close(stop)
|
||||
|
||||
// Fill buffer and never read to cause 5 consecutive timeouts
|
||||
for i := 0; i < 20; i++ {
|
||||
for range 20 {
|
||||
server.NotifySub(notify.Notification{
|
||||
Target: client.sub.ID,
|
||||
Message: "Timeout message",
|
||||
@@ -684,7 +685,7 @@ func Test_ConcurrentSubscriptions(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
clients := make([]*Client, 100)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
for i := range 100 {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
@@ -716,7 +717,7 @@ func Test_ConcurrentNotifications(t *testing.T) {
|
||||
messageCount := 50
|
||||
|
||||
// Send from multiple goroutines
|
||||
for i := 0; i < messageCount; i++ {
|
||||
for i := range messageCount {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
@@ -733,7 +734,7 @@ func Test_ConcurrentNotifications(t *testing.T) {
|
||||
// This is expected behavior - we're testing thread safety, not guaranteed delivery
|
||||
// Just verify we receive at least some messages without panicking or deadlocking
|
||||
received := 0
|
||||
timeout := time.After(2 * time.Second)
|
||||
timeout := time.After(500 * time.Millisecond)
|
||||
for received < messageCount {
|
||||
select {
|
||||
case <-notifications:
|
||||
@@ -751,7 +752,7 @@ func Test_ConcurrentCleanup(t *testing.T) {
|
||||
server := newTestServerWithNotifier(t)
|
||||
|
||||
// Create some clients
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
client, _ := server.GetClient("", "")
|
||||
// Set some to be old
|
||||
if i%2 == 0 {
|
||||
@@ -790,39 +791,34 @@ func Test_NoRaceConditions(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Create a few clients and read from them
|
||||
for i := 0; i < 5; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for range 5 {
|
||||
wg.Go(func() {
|
||||
client, _ := server.GetClient("", "")
|
||||
notifications, stop := client.Listen()
|
||||
defer close(stop)
|
||||
|
||||
// Actively read messages
|
||||
timeout := time.After(2 * time.Second)
|
||||
timeout := time.After(200 * time.Millisecond)
|
||||
for {
|
||||
select {
|
||||
case <-notifications:
|
||||
// Keep reading
|
||||
// Keep reading
|
||||
case <-timeout:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// Send a few notifications
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for j := 0; j < 20; j++ {
|
||||
wg.Go(func() {
|
||||
for range 10 {
|
||||
server.NotifyAll(notify.Notification{
|
||||
Message: "Stress test",
|
||||
})
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}()
|
||||
|
||||
})
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -948,7 +944,7 @@ func Test_ListenSignature(t *testing.T) {
|
||||
require.NotNil(t, stop)
|
||||
|
||||
// notifications should be receive-only
|
||||
_, ok := interface{}(notifications).(<-chan notify.Notification)
|
||||
_, ok := any(notifications).(<-chan notify.Notification)
|
||||
require.True(t, ok, "notifications should be receive-only channel")
|
||||
|
||||
// stop should be closeable
|
||||
@@ -964,7 +960,7 @@ func Test_BufferSize(t *testing.T) {
|
||||
defer close(stop)
|
||||
|
||||
// Send 10 messages without reading (buffer size is 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
server.NotifySub(notify.Notification{
|
||||
Target: client.sub.ID,
|
||||
Message: "Buffered",
|
||||
@@ -975,7 +971,7 @@ func Test_BufferSize(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Read all 10
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
select {
|
||||
case <-notifications:
|
||||
// Success
|
||||
|
||||
Reference in New Issue
Block a user