Skip to content

Commit

Permalink
Fixes for tests that depend on fast statsz for jetstream allocations …
Browse files Browse the repository at this point in the history
…and placements.

Minor fix for new test to cleanup cluster when done.

Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Jun 5, 2024
1 parent 958b61f commit 5401f76
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion server/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ const (
// FIXME(dlc) - make configurable.
var eventsHBInterval = 30 * time.Second

var statszRateLimit = 1 * time.Second
// Default minimum wait time for sending statsz
const defaultStatszRateLimit = 1 * time.Second

// Variable version so we can set in tests.
var statszRateLimit = defaultStatszRateLimit

type sysMsgHandler func(sub *subscription, client *client, acc *Account, subject, reply string, hdr, msg []byte)

Expand Down
10 changes: 8 additions & 2 deletions server/events_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2023 The NATS Authors
// Copyright 2018-2024 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -3540,10 +3540,16 @@ func Benchmark_GetHash(b *testing.B) {
}

func TestClusterSetupMsgs(t *testing.T) {
// Tests will set this general faster, but here we want default for production.
original := statszRateLimit
statszRateLimit = defaultStatszRateLimit
defer func() { statszRateLimit = original }()

numServers := 10
c := createClusterEx(t, false, 0, false, "cluster", numServers)
var totalOut int
defer shutdownCluster(c)

var totalOut int
for _, server := range c.servers {
totalOut += int(server.outMsgs)
}
Expand Down
3 changes: 3 additions & 0 deletions server/jetstream_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func init() {
maxElectionTimeout = 3500 * time.Millisecond
lostQuorumInterval = 2 * time.Second
lostQuorumCheck = 4 * hbInterval

// For statz and jetstream placement speedups as well.
statszRateLimit = time.Millisecond * 100
}

// Used to setup clusters of clusters for tests.
Expand Down
4 changes: 0 additions & 4 deletions server/jetstream_super_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1355,10 +1355,6 @@ func TestJetStreamSuperClusterPushConsumerInterest(t *testing.T) {
}

func TestJetStreamSuperClusterOverflowPlacement(t *testing.T) {
orgStatszRateLimit := statszRateLimit
statszRateLimit = time.Millisecond * 100
defer func() { statszRateLimit = orgStatszRateLimit }()

sc := createJetStreamSuperClusterWithTemplate(t, jsClusterMaxBytesTempl, 3, 3)
defer sc.shutdown()

Expand Down

0 comments on commit 5401f76

Please sign in to comment.