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