1
0
mirror of https://github.com/labstack/echo.git synced 2026-06-18 01:05:43 +02:00
Files
echo/middleware/randomstring_concurrent_test.go
Vishal Rana b1d65e40fe perf: optimize core hot paths (chain, context, binding, responses) (#3008)
Compile middleware chains once, zero-copy String/HTML/JSONP writes, reuse delayedStatusWriter + context store map, single-key QueryParam fast path, per-type bind metadata cache, precomputed HSTS header, pooled request-ID buffers. No public API changes. Also de-flakes TestStartConfig_WithListenerNetwork (ephemeral port).
2026-06-14 06:08:07 -07:00

38 lines
897 B
Go

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors
package middleware
import (
"strings"
"sync"
"testing"
)
// 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.
func TestRandomStringConcurrent(t *testing.T) {
const goroutines, iterations = 100, 300
var wg sync.WaitGroup
wg.Add(goroutines)
for g := 0; g < goroutines; g++ {
go func() {
defer wg.Done()
for i := 0; i < iterations; i++ {
s := randomString(32)
if len(s) != 32 {
t.Errorf("expected length 32, got %d (%q)", len(s), s)
return
}
for _, r := range s {
if !strings.ContainsRune(randomStringCharset, r) {
t.Errorf("char %q not in charset (%q)", r, s)
return
}
}
}
}()
}
wg.Wait()
}