Skip to content

Commit f326eee

Browse files
committed
actual fix for race issues
1 parent a8968b8 commit f326eee

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/github.com/getlantern/flashlight/config/initializer_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,32 @@ func TestInit(t *testing.T) {
1313
flags := make(map[string]interface{})
1414
flags["staging"] = true
1515

16-
var gotProxies bool
17-
var gotGlobal bool
16+
configChan := make(chan bool)
1817

18+
// Note these dispatch functions will receive multiple configs -- local ones,
19+
// embedded ones, and remote ones.
1920
proxiesDispatch := func(cfg interface{}) {
2021
proxies := cfg.(map[string]*client.ChainedServerInfo)
2122
assert.True(t, len(proxies) > 0)
22-
gotProxies = true
23+
configChan <- true
2324
}
2425
globalDispatch := func(cfg interface{}) {
2526
global := cfg.(*Global)
2627
assert.True(t, len(global.Client.MasqueradeSets) > 1)
27-
gotGlobal = true
28+
configChan <- true
2829
}
2930
Init(".", flags, &userConfig{}, proxiesDispatch, globalDispatch)
3031

31-
for i := 1; i <= 400; i++ {
32-
if !gotGlobal || !gotProxies {
33-
time.Sleep(50 * time.Millisecond)
32+
count := 0
33+
for i := 0; i < 2; i++ {
34+
select {
35+
case <-configChan:
36+
count++
37+
case <-time.After(time.Second * 12):
38+
assert.Fail(t, "Took too long to get configs")
3439
}
3540
}
41+
assert.Equal(t, 2, count)
3642
}
3743

3844
func TestStaging(t *testing.T) {

0 commit comments

Comments
 (0)