MCPcopy
hub / github.com/redis/go-redis / TestWantConnQueue_len_Concurrent

Function TestWantConnQueue_len_Concurrent

internal/pool/want_conn_test.go:875–917  ·  view source on GitHub ↗

TestWantConnQueue_len_Concurrent tests len() thread safety.

(t *testing.T)

Source from the content-addressed store, hash-verified

873
874// TestWantConnQueue_len_Concurrent tests len() thread safety.
875func TestWantConnQueue_len_Concurrent(t *testing.T) {
876 q := newWantConnQueue()
877 const numReaders = 10
878 const numWriters = 5
879 const operations = 100
880
881 var wg sync.WaitGroup
882
883 // Multiple readers calling len()
884 for i := 0; i < numReaders; i++ {
885 wg.Add(1)
886 go func() {
887 defer wg.Done()
888 for j := 0; j < operations; j++ {
889 _ = q.len() // Just read, don't care about value
890 time.Sleep(time.Microsecond)
891 }
892 }()
893 }
894
895 // Writers enqueueing
896 for i := 0; i < numWriters; i++ {
897 wg.Add(1)
898 go func() {
899 defer wg.Done()
900 for j := 0; j < operations; j++ {
901 w := &wantConn{
902 ctx: context.Background(),
903 result: make(chan wantConnResult, 1),
904 }
905 q.enqueue(w)
906 }
907 }()
908 }
909
910 wg.Wait()
911
912 // Verify final length is correct
913 expectedLength := numWriters * operations
914 if length := q.len(); length != expectedLength {
915 t.Errorf("final queue len() = %d, want %d", length, expectedLength)
916 }
917}

Callers

nothing calls this directly

Calls 5

newWantConnQueueFunction · 0.85
enqueueMethod · 0.80
WaitMethod · 0.80
AddMethod · 0.65
lenMethod · 0.45

Tested by

no test coverage detected