Skip to content

Commit 8d896f4

Browse files
committed
etcd_docker 3: Incorporate docker based etcd integration package into… (#4147)
PR 3 for #4144 High level approach is as described in #4144 . This PR incorporates the new test package into our unittests. Usage is via the `etcdintegration` package, which makes it transparent to the test code; it simply gets an etcd server started via different means. One piece of weirdness to call out here: the package currently relies on autosync being *disabled* on the client side. This is because the advertise client URL (aka what etcd tells clients to connect to) isn't correct for the open port on the host. That is we have: - etcd: listen on container port 0.0.0.0:2379, advertise 0.0.0.0:2379 - docker: expose etcd port 2379 to 0.0.0.0:0 on host machine (random free port) - client: connect to etcd via host machine. We could probably make this better. commit-id:263fed13
1 parent fbd938b commit 8d896f4

27 files changed

Lines changed: 255 additions & 225 deletions

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ require (
7070
go.etcd.io/etcd/client/pkg/v3 v3.6.0-alpha.0
7171
go.etcd.io/etcd/client/v3 v3.6.0-alpha.0
7272
go.etcd.io/etcd/server/v3 v3.6.0-alpha.0
73-
go.etcd.io/etcd/tests/v3 v3.6.0-alpha.0
7473
go.opentelemetry.io/collector v0.45.0
7574
go.opentelemetry.io/otel v1.4.1
7675
go.opentelemetry.io/otel/bridge/opentracing v1.4.1
@@ -121,7 +120,6 @@ require (
121120
github.com/go-playground/locales v0.13.0 // indirect
122121
github.com/go-playground/universal-translator v0.17.0 // indirect
123122
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
124-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
125123
github.com/google/btree v1.0.1 // indirect
126124
github.com/gorilla/handlers v1.5.1 // indirect
127125
github.com/gorilla/websocket v1.4.2 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,6 @@ go.etcd.io/etcd/raft/v3 v3.6.0-alpha.0 h1:BQ6CnNP4pIpy5rusFlTBxAacDgPXhuiHFwoTsB
15921592
go.etcd.io/etcd/raft/v3 v3.6.0-alpha.0/go.mod h1:/kZdrBXlc5fUgYXfIEQ0B5sb7ejXPKbtF4jWzF1exiQ=
15931593
go.etcd.io/etcd/server/v3 v3.6.0-alpha.0 h1:BQUVqBqNFZZyrRbfydrRLzq9hYvCcRj97SsX1YwD7CA=
15941594
go.etcd.io/etcd/server/v3 v3.6.0-alpha.0/go.mod h1:3QM2rLq3B3hSXmVEvgVt3vEEbG/AumSs0Is7EgrlKzU=
1595-
go.etcd.io/etcd/tests/v3 v3.6.0-alpha.0 h1:3qrZ3p/E7CxdV1kKtAU75hHOcUoXcSTwC7ELKWyzMJo=
1596-
go.etcd.io/etcd/tests/v3 v3.6.0-alpha.0/go.mod h1:hFQkP/cTsZIXXvUv+BsGHZ3TK+76XZMi5GToYA94iac=
15971595
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
15981596
go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
15991597
go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=

src/aggregator/integration/custom_aggregations_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2016 Uber Technologies, Inc.
44
//
@@ -68,7 +68,6 @@ func testCustomAggregations(t *testing.T, metadataFns [4]metadataFn) {
6868
if testing.Short() {
6969
t.SkipNow()
7070
}
71-
7271
aggTypesOpts := aggregation.NewTypesOptions().
7372
SetCounterTypeStringTransformFn(aggregation.SuffixTransform).
7473
SetTimerTypeStringTransformFn(aggregation.SuffixTransform).
@@ -179,7 +178,7 @@ func testCustomAggregations(t *testing.T, metadataFns [4]metadataFn) {
179178
// must be the longer than the lowest resolution across all policies.
180179
finalTime := end.Add(6 * time.Second)
181180
clock.SetNow(finalTime)
182-
time.Sleep(6 * time.Second)
181+
time.Sleep(waitForDataToFlush)
183182

184183
require.NoError(t, client.close())
185184

src/aggregator/integration/election.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import (
2626
"github.com/m3db/m3/src/cluster/services"
2727
"github.com/m3db/m3/src/cluster/services/leader"
2828

29+
integration "github.com/m3db/m3/src/integration/resources/docker/dockerexternal/etcdintegration"
2930
"github.com/stretchr/testify/require"
3031
clientv3 "go.etcd.io/etcd/client/v3"
31-
"go.etcd.io/etcd/tests/v3/framework/integration"
3232
)
3333

3434
var (
@@ -40,27 +40,38 @@ var (
4040
)
4141

4242
type testCluster struct {
43-
t *testing.T
44-
cluster *integration.Cluster
43+
t *testing.T
44+
cluster *integration.Cluster
45+
leaderService services.LeaderService
4546
}
4647

4748
func newTestCluster(t *testing.T) *testCluster {
4849
integration.BeforeTestExternal(t)
49-
return &testCluster{
50+
cluster := &testCluster{
5051
t: t,
5152
cluster: integration.NewCluster(t, &integration.ClusterConfig{
5253
Size: testClusterSize,
5354
}),
5455
}
56+
return cluster
5557
}
5658

5759
func (tc *testCluster) LeaderService() services.LeaderService {
60+
if tc.leaderService != nil {
61+
return tc.leaderService
62+
}
63+
5864
svc, err := leader.NewService(tc.etcdClient(), tc.options())
5965
require.NoError(tc.t, err)
60-
return svc
66+
tc.leaderService = svc
67+
return tc.leaderService
6168
}
6269

6370
func (tc *testCluster) Close() {
71+
if tc.leaderService != nil {
72+
// amainsd: check error here!
73+
_ = tc.leaderService.Close()
74+
}
6475
tc.cluster.Terminate(tc.t)
6576
}
6677

src/aggregator/integration/metadata_change_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2016 Uber Technologies, Inc.
44
//
@@ -138,7 +138,7 @@ func testMetadataChange(t *testing.T, oldMetadataFn, newMetadataFn metadataFn) {
138138
// must be the longer than the lowest resolution across all policies.
139139
finalTime := end.Add(6 * time.Second)
140140
clock.SetNow(finalTime)
141-
time.Sleep(6 * time.Second)
141+
time.Sleep(waitForDataToFlush)
142142

143143
require.NoError(t, client.close())
144144

src/aggregator/integration/multi_client_one_type_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2016 Uber Technologies, Inc.
44
//
@@ -126,7 +126,7 @@ func testMultiClientOneType(t *testing.T, metadataFn metadataFn) {
126126
// must be the longer than the lowest resolution across all policies.
127127
finalTime := stop.Add(6 * time.Second)
128128
clock.SetNow(finalTime)
129-
time.Sleep(4 * time.Second)
129+
time.Sleep(waitForDataToFlush)
130130

131131
for i := 0; i < numClients; i++ {
132132
require.NoError(t, clients[i].close())

src/aggregator/integration/one_client_multi_type_forwarded_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2018 Uber Technologies, Inc.
44
//
@@ -121,7 +121,7 @@ func TestOneClientMultiTypeForwardedMetrics(t *testing.T) {
121121
// Move time forward and wait for flushing to happen.
122122
finalTime := stop.Add(2 * time.Second)
123123
clock.SetNow(finalTime)
124-
time.Sleep(2 * time.Second)
124+
time.Sleep(waitForDataToFlush)
125125

126126
require.NoError(t, client.close())
127127

src/aggregator/integration/one_client_multi_type_timed_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2018 Uber Technologies, Inc.
44
//
@@ -119,7 +119,7 @@ func TestOneClientMultiTypeTimedMetrics(t *testing.T) {
119119
// Move time forward and wait for flushing to happen.
120120
finalTime := stop.Add(time.Minute + 2*time.Second)
121121
clock.SetNow(finalTime)
122-
time.Sleep(2 * time.Second)
122+
time.Sleep(waitForDataToFlush)
123123

124124
require.NoError(t, client.close())
125125

src/aggregator/integration/one_client_multi_type_untimed_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2016 Uber Technologies, Inc.
44
//
@@ -26,9 +26,17 @@ import (
2626
"testing"
2727
"time"
2828

29+
"github.com/m3db/m3/src/cluster/placement"
30+
2931
"github.com/stretchr/testify/require"
32+
)
3033

31-
"github.com/m3db/m3/src/cluster/placement"
34+
const (
35+
// waitForDataToFlush is the amount of time we will wait in these tests between finishing writing data to
36+
// the aggregator, and attempting to assert that data went through.
37+
// The aggregator generally, and these tests specifically are quite sensitive to time.
38+
// The tests probably need a bit of a rethink to wait on (or poll for) an actual condition instead of sleeping.
39+
waitForDataToFlush = 10 * time.Second
3240
)
3341

3442
func TestOneClientMultiTypeUntimedMetricsWithStagedMetadatas(t *testing.T) {
@@ -114,7 +122,7 @@ func testOneClientMultiType(t *testing.T, metadataFn metadataFn) {
114122
// must be the longer than the lowest resolution across all policies.
115123
finalTime := stop.Add(6 * time.Second)
116124
clock.SetNow(finalTime)
117-
time.Sleep(4 * time.Second)
125+
time.Sleep(waitForDataToFlush)
118126

119127
require.NoError(t, client.close())
120128

src/aggregator/integration/one_client_passthru_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2020 Uber Technologies, Inc.
44
//

0 commit comments

Comments
 (0)