-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_test.go
More file actions
51 lines (41 loc) · 1.09 KB
/
client_test.go
File metadata and controls
51 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package client
import (
"context"
"os"
"sync"
"testing"
"time"
)
// TestConcurrentConnections tests for race conditions when creating multiple connections
func TestConcurrentConnections(t *testing.T) {
// Skip unless explicitly enabled
if os.Getenv("RUN_RECONNECTION_TEST") != "true" {
t.Skip("Skipping reconnection test. Set RUN_RECONNECTION_TEST=true to run")
}
apiKey := os.Getenv("FIBER_API_KEY")
if apiKey == "" {
t.Skip("FIBER_API_KEY environment variable not set")
}
target := "beta.fiberapi.io:8080"
var wg sync.WaitGroup
numClients := 5
// Create multiple clients concurrently
for i := 0; i < numClients; i++ {
wg.Add(1)
go func(clientID int) {
defer wg.Done()
client := NewClient(target, apiKey)
defer func() {
if err := client.Close(); err != nil {
t.Logf("Client %d failed to close cleanly: %v", clientID, err)
}
}()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := client.Connect(ctx); err != nil {
t.Errorf("Client %d failed to connect: %v", clientID, err)
}
}(i)
}
wg.Wait()
}