Skip to content

Commit

Permalink
PMM-7 fix tests and a small improvement. (#720)
Browse files Browse the repository at this point in the history
* PMM-7 fix tests and a small improvement.

* PMM-7 use docker compose v2.

* PMM-7 add extra wait.

* PMM-7 stabilize tests.
  • Loading branch information
BupycHuk authored Oct 9, 2023
1 parent 4cbba0f commit ccd4642
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ jobs:
- name: Test
run: |
TEST_MONGODB_IMAGE=${{ matrix.image }} make test-cluster
sleep 10
make test-race
make test-cluster-clean
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test-race: env ## Run all tests with race flag.
go test -race -v -timeout 30s ./...

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
docker-compose up -d
docker compose up -d --wait

test-cluster-clean: env ## Stops MongoDB test cluster.
docker-compose down --remove-orphans
docker compose down --remove-orphans
4 changes: 2 additions & 2 deletions exporter/currentop_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestCurrentopCollector(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var wg sync.WaitGroup
Expand All @@ -48,7 +48,7 @@ func TestCurrentopCollector(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 3; i++ {
for i := 0; i < 300; i++ {
coll := fmt.Sprintf("testcol_%02d", i)
_, err := database.Collection(coll).InsertOne(ctx, bson.M{"f1": 1, "f2": "2"})
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/v1_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ func replSetMetrics(m bson.M) []prometheus.Metric {
for _, m := range repl.Members {
if m.StateStr == "PRIMARY" {
primaryOpTime = m.OptimeDate.Time()
gotPrimary = true
gotPrimary = !primaryOpTime.IsZero()

break
}
Expand Down

0 comments on commit ccd4642

Please sign in to comment.