Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b51eec3

Browse files
committed
all: fixing test stability
Change-Id: I7b8aad80ef022a0f7c0067488682c8c65441a090
1 parent 4ed6339 commit b51eec3

File tree

15 files changed

+63
-22
lines changed

15 files changed

+63
-22
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ require (
8686
k8s.io/api v0.33.3
8787
k8s.io/apimachinery v0.33.3
8888
k8s.io/client-go v0.33.3
89-
storj.io/common v0.0.0-20250808122759-804533d519c1
89+
storj.io/common v0.0.0-20250905132913-dad2ec895b75
9090
storj.io/drpc v0.0.35-0.20250513201419-f7819ea69b55
9191
storj.io/eventkit v0.0.0-20250410172343-61f26d3de156
9292
storj.io/minmaxheap v0.0.0-20250403032542-1e24a6fe9c16

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,8 +2214,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.6.0 h1:IUA9nvMmnKWcj5jl84xn+T5MnlZKThmUW
22142214
sigs.k8s.io/structured-merge-diff/v4 v4.6.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps=
22152215
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
22162216
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
2217-
storj.io/common v0.0.0-20250808122759-804533d519c1 h1:z7ZjU+TlPZ2Lq2S12hT6+Fr7jFsBxPMrPBH4zZpZuUA=
2218-
storj.io/common v0.0.0-20250808122759-804533d519c1/go.mod h1:YNr7/ty6CmtpG5C9lEPtPXK3hOymZpueCb9QCNuPMUY=
2217+
storj.io/common v0.0.0-20250905132913-dad2ec895b75 h1:T/0FZByS/sdeDJJqC2z1v4qwNIjDijWi0g+7XcrsJ4o=
2218+
storj.io/common v0.0.0-20250905132913-dad2ec895b75/go.mod h1:YNr7/ty6CmtpG5C9lEPtPXK3hOymZpueCb9QCNuPMUY=
22192219
storj.io/drpc v0.0.35-0.20250513201419-f7819ea69b55 h1:8OE12DvUnB9lfZcHe7IDGsuhjrY9GBAr964PVHmhsro=
22202220
storj.io/drpc v0.0.35-0.20250513201419-f7819ea69b55/go.mod h1:Y9LZaa8esL1PW2IDMqJE7CFSNq7d5bQ3RI7mGPtmKMg=
22212221
storj.io/eventkit v0.0.0-20250410172343-61f26d3de156 h1:5MZ0CyMbG6Pi0rRzUWVG6dvpXjbBYEX2oyXuj+tT+sk=

private/testplanet/run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.C
118118
testmonkit.Run(t.Context(), t, func(parent context.Context) {
119119
pprof.Do(parent, pprof.Labels("test", t.Name()), func(parent context.Context) {
120120
jobqtest.WithServer(t, &jobqtest.ServerOptions{
121-
Host: planetConfig.Host,
121+
Host: planetConfig.Host,
122+
Timeout: config.Timeout,
122123
}, func(ctx *testcontext.Context, srv *jobqtest.TestServer) {
123124
timeout := config.Timeout
124125
if timeout == 0 {
125126
timeout = testcontext.DefaultTimeout
126127
}
127128
ctx = testcontext.NewWithContextAndTimeout(ctx, t, timeout)
129+
defer ctx.Cleanup()
128130

129131
reconfig := func(log *zap.Logger, index int, config *satellite.Config) {
130132
config.JobQueue = jobq.Config{

satellite/console/service_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestService(t *testing.T) {
6868
}
6969
testplanet.Run(t, testplanet.Config{
7070
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 4,
71+
Timeout: -1,
7172
Reconfigure: testplanet.Reconfigure{
7273
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
7374
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripe.MockCouponID1

satellite/jobq/jobqtest/jobqtest.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type ServerOptions struct {
3434
MaxMemPerPlacement memory.Size
3535
InitAlloc memory.Size
3636
MemReleaseThreshold memory.Size
37+
38+
// Timeout for the testcontext.
39+
Timeout time.Duration
3740
}
3841

3942
// TestServer wraps a jobq server together with its setup information, so that
@@ -91,6 +94,9 @@ func WithServer(t *testing.T, options *ServerOptions, f func(ctx *testcontext.Co
9194
if options.MemReleaseThreshold == 0 {
9295
options.MemReleaseThreshold = 1e6
9396
}
97+
if options.Timeout == 0 {
98+
options.Timeout = testcontext.DefaultTimeout
99+
}
94100

95101
host := options.Host
96102
if host == "" {
@@ -128,7 +134,9 @@ func WithServer(t *testing.T, options *ServerOptions, f func(ctx *testcontext.Co
128134

129135
testmonkit.Run(ctx, t, func(parent context.Context) {
130136
pprof.Do(parent, pprof.Labels("test", t.Name()), func(parent context.Context) {
131-
f(testcontext.New(t), testSrv)
137+
ctx := testcontext.NewWithContextAndTimeout(parent, t, options.Timeout)
138+
defer ctx.Cleanup()
139+
f(ctx, testSrv)
132140
})
133141
})
134142

satellite/metainfo/endpoint.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ func TestingNewAPIKeysEndpoint(log *zap.Logger, apiKeys APIKeys) *Endpoint {
214214
}
215215
}
216216

217+
// TestingGetLimiterCache returns the limiter cache for testing purposes.
218+
func (endpoint *Endpoint) TestingGetLimiterCache() *lrucache.ExpiringLRUOf[*rate.Limiter] {
219+
return endpoint.limiterCache
220+
}
221+
217222
// Run manages the internal dependencies of the endpoint such as the
218223
// success tracker.
219224
func (endpoint *Endpoint) Run(ctx context.Context) error {

satellite/metainfo/endpoint_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,17 +617,15 @@ func TestRateLimit_ProjectRateLimitOverrideCachedExpired(t *testing.T) {
617617
Reconfigure: testplanet.Reconfigure{
618618
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
619619
config.Metainfo.RateLimiter.Rate = 2
620-
config.Metainfo.RateLimiter.CacheExpiration = time.Second
620+
config.Metainfo.RateLimiter.CacheExpiration = 5 * time.Second
621621
},
622622
SatelliteDBOptions: testplanet.SatelliteDBDisableCaches,
623623
},
624624
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
625625
ul := planet.Uplinks[0]
626626
satellite := planet.Satellites[0]
627-
628-
// TODO find a way to reset limiter before test is executed, currently
629-
// testplanet is doing one additional request to get access
630-
time.Sleep(2 * time.Second)
627+
limiter := satellite.Metainfo.Endpoint.TestingGetLimiterCache()
628+
limiter.Reset()
631629

632630
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
633631
require.NoError(t, err)
@@ -656,7 +654,7 @@ func TestRateLimit_ProjectRateLimitOverrideCachedExpired(t *testing.T) {
656654
err = satellite.DB.Console().Projects().Update(ctx, &projects[0])
657655
require.NoError(t, err)
658656

659-
time.Sleep(2 * time.Second)
657+
time.Sleep(6 * time.Second)
660658

661659
var group2 errs2.Group
662660

satellite/overlay/uploadselection_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const (
5757
)
5858

5959
func TestRefresh(t *testing.T) {
60-
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
60+
satellitedbtest.RunWithConfig(t, satellitedbtest.Config{
61+
NonParallel: true,
62+
}, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
6163
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
6264
db.OverlayCache(),
6365
lowStaleness,
@@ -84,8 +86,6 @@ func TestRefresh(t *testing.T) {
8486
monkit.Default.Stats(func(key monkit.SeriesKey, field string, val float64) {
8587
if key.Measurement == "placement" && (field == "UploadCount" || field == "Count") {
8688
require.Equal(t, float64(nodeCount), val)
87-
require.Equal(t, float64(nodeCount), val)
88-
8989
}
9090
})
9191
require.NoError(t, err)

satellite/repair/repairer/segments_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestSegmentRepairPlacement(t *testing.T) {
4848
},
4949
),
5050
},
51+
Timeout: -1,
5152
ExerciseJobq: true,
5253
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
5354
// disable pinging the Satellite so we can control storagenode status.

satellite/satellitedb/satellitedbtest/run.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,26 @@ func CreateMetabaseDBOnTopOf(ctx context.Context, log *zap.Logger, tempDB *dbuti
231231
// Run method will iterate over all supported databases. Will establish
232232
// connection and will create tables for each DB.
233233
func Run(t *testing.T, test func(ctx *testcontext.Context, t *testing.T, db satellite.DB)) {
234-
t.Parallel()
234+
RunWithConfig(t, Config{}, test)
235+
}
236+
237+
// Config allows customizing Run behaviour.
238+
type Config struct {
239+
NonParallel bool
240+
}
241+
242+
// RunWithConfig method will iterate over all supported databases. Will establish
243+
// connection and will create tables for each DB.
244+
func RunWithConfig(t *testing.T, cfg Config, test func(ctx *testcontext.Context, t *testing.T, db satellite.DB)) {
245+
if !cfg.NonParallel {
246+
t.Parallel()
247+
}
235248
for _, dbInfo := range Databases() {
236249
dbInfo := dbInfo
237250
t.Run(dbInfo.Name, func(t *testing.T) {
238-
t.Parallel()
251+
if !cfg.NonParallel {
252+
t.Parallel()
253+
}
239254

240255
ctx := testcontext.New(t)
241256
defer ctx.Cleanup()

0 commit comments

Comments
 (0)