mirror of https://github.com/status-im/consul.git
Remove unnecessary goroutine in flaky test
The watch is established in a background goroutine and the first assertion proves that the watcher is active so there is no reason for the update to happen in a racy goroutine. Note that this does not completely remove the race condition as the first call to testGetConfigValTimeout could time out before a config is returned.
This commit is contained in:
parent
4e292b7b72
commit
a5fe2125e9
|
@ -4,7 +4,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent"
|
"github.com/hashicorp/consul/agent"
|
||||||
|
@ -143,23 +142,17 @@ func TestAgentConfigWatcherSidecarProxy(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, expectCfg, cfg)
|
require.Equal(t, expectCfg, cfg)
|
||||||
|
|
||||||
// Now keep watching and update the config.
|
// Now keep watching and update the config.
|
||||||
go func() {
|
reg.Connect.SidecarService.Proxy.Upstreams = append(reg.Connect.SidecarService.Proxy.Upstreams,
|
||||||
// Wait for watcher to be watching
|
api.Upstream{
|
||||||
time.Sleep(20 * time.Millisecond)
|
DestinationName: "cache",
|
||||||
reg.Connect.SidecarService.Proxy.Upstreams = append(reg.Connect.SidecarService.Proxy.Upstreams,
|
LocalBindPort: 9292,
|
||||||
api.Upstream{
|
LocalBindAddress: "127.10.10.10",
|
||||||
DestinationName: "cache",
|
})
|
||||||
LocalBindPort: 9292,
|
reg.Connect.SidecarService.Proxy.Config["local_connect_timeout_ms"] = 444
|
||||||
LocalBindAddress: "127.10.10.10",
|
require.NoError(t, agent.ServiceRegister(reg))
|
||||||
})
|
|
||||||
reg.Connect.SidecarService.Proxy.Config["local_connect_timeout_ms"] = 444
|
|
||||||
err := agent.ServiceRegister(reg)
|
|
||||||
require.NoError(t, err)
|
|
||||||
}()
|
|
||||||
|
|
||||||
cfg = testGetConfigValTimeout(t, w, 2*time.Second)
|
cfg = testGetConfigValTimeout(t, w, 2*time.Second)
|
||||||
|
|
||||||
|
@ -173,7 +166,7 @@ func TestAgentConfigWatcherSidecarProxy(t *testing.T) {
|
||||||
})
|
})
|
||||||
expectCfg.PublicListener.LocalConnectTimeoutMs = 444
|
expectCfg.PublicListener.LocalConnectTimeoutMs = 444
|
||||||
|
|
||||||
assert.Equal(t, expectCfg, cfg)
|
require.Equal(t, expectCfg, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGetConfigValTimeout(t *testing.T, w ConfigWatcher,
|
func testGetConfigValTimeout(t *testing.T, w ConfigWatcher,
|
||||||
|
|
Loading…
Reference in New Issue