Skip to content

Commit 9ab1e2d

Browse files
authored
Merge pull request #14 from e-max/map_race_#13
test on map race #13
2 parents c95d8ef + c28e14d commit 9ab1e2d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

stats_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"net/http/httptest"
77
"testing"
8+
"time"
89

910
"github.com/stretchr/testify/assert"
1011
)
@@ -61,3 +62,41 @@ func TestGetStats(t *testing.T) {
6162

6263
assert.Equal(t, data["total_count"].(float64), float64(1))
6364
}
65+
66+
func TestRace(t *testing.T) {
67+
s := New()
68+
69+
ch1 := make(chan bool)
70+
ch2 := make(chan bool)
71+
72+
go func() {
73+
now := time.Now()
74+
for true {
75+
select {
76+
case _ = <-ch1:
77+
return
78+
default:
79+
s.EndWithStatus(now, 200)
80+
81+
}
82+
}
83+
84+
}()
85+
86+
go func() {
87+
dt := s.Data()
88+
for true {
89+
select {
90+
case _ = <-ch2:
91+
return
92+
default:
93+
_ = dt.TotalStatusCodeCount["200"]
94+
}
95+
}
96+
}()
97+
98+
time.Sleep(time.Second)
99+
100+
ch1 <- true
101+
ch2 <- true
102+
}

0 commit comments

Comments
 (0)