MCPcopy
hub / github.com/labstack/echo / TestRandomStringConcurrent

Function TestRandomStringConcurrent

middleware/randomstring_concurrent_test.go:14–37  ·  view source on GitHub ↗

TestRandomStringConcurrent guards the pooled scratch buffers in randomString: concurrent callers must not share/alias a buffer and corrupt each other's output. Run with -race.

(t *testing.T)

Source from the content-addressed store, hash-verified

12// TestRandomStringConcurrent guards the pooled scratch buffers in randomString: concurrent callers
13// must not share/alias a buffer and corrupt each other's output. Run with -race.
14func TestRandomStringConcurrent(t *testing.T) {
15 const goroutines, iterations = 100, 300
16 var wg sync.WaitGroup
17 wg.Add(goroutines)
18 for g := 0; g < goroutines; g++ {
19 go func() {
20 defer wg.Done()
21 for i := 0; i < iterations; i++ {
22 s := randomString(32)
23 if len(s) != 32 {
24 t.Errorf("expected length 32, got %d (%q)", len(s), s)
25 return
26 }
27 for _, r := range s {
28 if !strings.ContainsRune(randomStringCharset, r) {
29 t.Errorf("char %q not in charset (%q)", r, s)
30 return
31 }
32 }
33 }
34 }()
35 }
36 wg.Wait()
37}

Callers

nothing calls this directly

Calls 2

randomStringFunction · 0.85
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…