Skip to content

Commit ccd4642

Browse files
authored
PMM-7 fix tests and a small improvement. (#720)
* PMM-7 fix tests and a small improvement. * PMM-7 use docker compose v2. * PMM-7 add extra wait. * PMM-7 stabilize tests.
1 parent 4cbba0f commit ccd4642

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ jobs:
4141
- name: Test
4242
run: |
4343
TEST_MONGODB_IMAGE=${{ matrix.image }} make test-cluster
44+
sleep 10
4445
make test-race
4546
make test-cluster-clean

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test-race: env ## Run all tests with race flag.
104104
go test -race -v -timeout 30s ./...
105105

106106
test-cluster: env ## Starts MongoDB test cluster. Use env var TEST_MONGODB_IMAGE to set flavor and version. Example: TEST_MONGODB_IMAGE=mongo:3.6 make test-cluster
107-
docker-compose up -d
107+
docker compose up -d --wait
108108

109109
test-cluster-clean: env ## Stops MongoDB test cluster.
110-
docker-compose down --remove-orphans
110+
docker compose down --remove-orphans

exporter/currentop_collector_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
func TestCurrentopCollector(t *testing.T) {
34-
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
34+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
3535
defer cancel()
3636

3737
var wg sync.WaitGroup
@@ -48,7 +48,7 @@ func TestCurrentopCollector(t *testing.T) {
4848
wg.Add(1)
4949
go func() {
5050
defer wg.Done()
51-
for i := 0; i < 3; i++ {
51+
for i := 0; i < 300; i++ {
5252
coll := fmt.Sprintf("testcol_%02d", i)
5353
_, err := database.Collection(coll).InsertOne(ctx, bson.M{"f1": 1, "f2": "2"})
5454
assert.NoError(t, err)

exporter/v1_compatibility.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ func replSetMetrics(m bson.M) []prometheus.Metric {
971971
for _, m := range repl.Members {
972972
if m.StateStr == "PRIMARY" {
973973
primaryOpTime = m.OptimeDate.Time()
974-
gotPrimary = true
974+
gotPrimary = !primaryOpTime.IsZero()
975975

976976
break
977977
}

0 commit comments

Comments
 (0)