Skip to content

Commit 222a29a

Browse files
authored
CBG-4686 increase wait time for windows/race (#7600)
1 parent eed8a89 commit 222a29a

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

base/util_test_norace.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2025-Present Couchbase, Inc.
2+
//
3+
// Use of this software is governed by the Business Source License included
4+
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
5+
// in that file, in accordance with the Business Source License, use of this
6+
// software will be governed by the Apache License, Version 2.0, included in
7+
// the file licenses/APL2.txt.
8+
9+
//go:build !race
10+
// +build !race
11+
12+
package base
13+
14+
import "testing"
15+
16+
// IsRaceDetectorEnabled returns true if compiled with -race. Intended to be used for testing only.
17+
func IsRaceDetectorEnabled(t *testing.T) bool {
18+
return false
19+
}

base/util_test_race.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2025-Present Couchbase, Inc.
2+
//
3+
// Use of this software is governed by the Business Source License included
4+
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
5+
// in that file, in accordance with the Business Source License, use of this
6+
// software will be governed by the Apache License, Version 2.0, included in
7+
// the file licenses/APL2.txt.
8+
9+
//go:build race
10+
// +build race
11+
12+
package base
13+
14+
import "testing"
15+
16+
// IsRaceDetectorEnabled returns true if compiled with -race. Intended to be used for testing only
17+
func IsRaceDetectorEnabled(t *testing.T) bool {
18+
return true
19+
}

db/database_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"encoding/json"
1414
"fmt"
1515
"log"
16+
"runtime"
1617
"runtime/debug"
1718
"sort"
1819
"strconv"
@@ -3363,6 +3364,12 @@ func TestUpdateCalculatedStatsPanic(t *testing.T) {
33633364
}
33643365

33653366
func Test_waitForBackgroundManagersToStop(t *testing.T) {
3367+
// use testing/synctest to have fake time once go 1.25 is available. In the meantime, windows and -race are
3368+
// slow enough thatthe time is increased, but this keeps interactive testing fast.
3369+
waitTime := 50 * time.Millisecond
3370+
if runtime.GOOS == "windows" || base.IsRaceDetectorEnabled(t) {
3371+
waitTime = 1 * time.Second
3372+
}
33663373
t.Run("single unstoppable process", func(t *testing.T) {
33673374
bgMngr := &BackgroundManager{
33683375
name: "test_unstoppable_runner",
@@ -3375,7 +3382,7 @@ func Test_waitForBackgroundManagersToStop(t *testing.T) {
33753382
require.NoError(t, err)
33763383

33773384
startTime := time.Now()
3378-
deadline := 50 * time.Millisecond
3385+
deadline := waitTime
33793386
waitForBackgroundManagersToStop(ctx, deadline, []*BackgroundManager{bgMngr})
33803387
assert.Greater(t, time.Since(startTime), deadline)
33813388
assert.Equal(t, BackgroundProcessStateStopping, bgMngr.GetRunState())
@@ -3393,7 +3400,7 @@ func Test_waitForBackgroundManagersToStop(t *testing.T) {
33933400
require.NoError(t, err)
33943401

33953402
startTime := time.Now()
3396-
deadline := 100 * time.Millisecond
3403+
deadline := waitTime
33973404
waitForBackgroundManagersToStop(ctx, deadline, []*BackgroundManager{bgMngr})
33983405
assert.Less(t, time.Since(startTime), deadline)
33993406
assert.Equal(t, BackgroundProcessStateStopped, bgMngr.GetRunState())
@@ -3421,7 +3428,7 @@ func Test_waitForBackgroundManagersToStop(t *testing.T) {
34213428
require.NoError(t, err)
34223429

34233430
startTime := time.Now()
3424-
deadline := 100 * time.Millisecond
3431+
deadline := waitTime
34253432
waitForBackgroundManagersToStop(ctx, deadline, []*BackgroundManager{stoppableBgMngr, unstoppableBgMngr})
34263433
assert.Greater(t, time.Since(startTime), deadline)
34273434
assert.Equal(t, BackgroundProcessStateStopped, stoppableBgMngr.GetRunState())

0 commit comments

Comments
 (0)