This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-09-13 04:20:00 +03:00
parent 4845b77177
commit 65b7983d7a
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7

View File

@ -18,6 +18,7 @@ import (
) )
func TestAccessLogPrint_Simple(t *testing.T) { func TestAccessLogPrint_Simple(t *testing.T) {
t.Parallel()
const goroutinesN = 420 const goroutinesN = 420
w := new(bytes.Buffer) w := new(bytes.Buffer)
@ -26,12 +27,17 @@ func TestAccessLogPrint_Simple(t *testing.T) {
ac.ResponseBody = true ac.ResponseBody = true
ac.Clock = TClock(time.Time{}) ac.Clock = TClock(time.Time{})
var expected string var (
var expectedLines int expected string
var mu sync.Mutex expectedLines int
for i := 0; i < goroutinesN; i++ { mu sync.Mutex
wg sync.WaitGroup
)
wg.Add(goroutinesN)
for i := 0; i < goroutinesN; i++ {
go func() { go func() {
defer wg.Done()
ac.Print( ac.Print(
nil, nil,
1*time.Second, 1*time.Second,
@ -61,9 +67,8 @@ func TestAccessLogPrint_Simple(t *testing.T) {
mu.Unlock() mu.Unlock()
} }
// time.Sleep(1 * time.Second) wg.Wait()
// just to fire at least some routines (CI: travis). ac.Close() // TODO: Close waits for current messages but does allow future writes, I should change that.
ac.Close()
if got := atomic.LoadUint32(&ac.remaining); got > 0 { // test wait. if got := atomic.LoadUint32(&ac.remaining); got > 0 { // test wait.
t.Fatalf("expected remaining: %d but got: %d", 0, got) t.Fatalf("expected remaining: %d but got: %d", 0, got)