Fixed some flappers

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2019-05-24 08:54:18 -06:00
parent d779a0bd38
commit 48c3f7f846
6 changed files with 68 additions and 64 deletions

View File

@@ -676,7 +676,12 @@ func TestSystemAccountConnectionLimitsServersStaggered(t *testing.T) {
// Trigger a load of the user account on the new server
// NOTE: If we do not load the user, the user can be the first
// to request this account, hence the connection will succeed.
sb.LookupAccount(pub)
checkFor(t, time.Second, 15*time.Millisecond, func() error {
if acc, err := sb.LookupAccount(pub); acc == nil || err != nil {
return fmt.Errorf("LookupAccount did not return account or failed, err=%v", err)
}
return nil
})
// Expect this to fail.
urlB := fmt.Sprintf("nats://%s:%d", optsB.Host, optsB.Port)

View File

@@ -2366,7 +2366,7 @@ func (s *Server) gatewayHandleSubjectNoInterest(c *client, acc *Account, accName
if _, alreadySent := e.ni[string(subject)]; !alreadySent {
// TODO(ik): pick some threshold as to when
// we need to switch mode
if len(e.ni) > gatewayMaxRUnsubBeforeSwitch {
if len(e.ni) >= gatewayMaxRUnsubBeforeSwitch {
// If too many RS-, switch to all-subs-mode.
c.gatewaySwitchAccountToSendAllSubs(e, accName)
} else {

View File

@@ -898,12 +898,8 @@ func TestJWTAccountImportActivationExpires(t *testing.T) {
activation.ImportType = jwt.Stream
now := time.Now()
activation.IssuedAt = now.Add(-10 * time.Second).Unix()
// These are second resolution. So check that we actually expire in a second and adjust if needed.
expires := now.Add(time.Second).Unix()
if expires == now.Unix() {
expires++
}
activation.Expires = expires
// These are second resolution. So round up before adding a second.
activation.Expires = now.Round(time.Second).Add(time.Second).Unix()
actJWT, err := activation.Encode(fooKP)
if err != nil {
t.Fatalf("Error generating activation token: %v", err)
@@ -938,23 +934,26 @@ func TestJWTAccountImportActivationExpires(t *testing.T) {
parseAsync("SUB import.foo 1\r\nPING\r\n")
expectPong(cr)
checkShadow := func(expected int) {
checkShadow := func(t *testing.T, expected int) {
t.Helper()
c.mu.Lock()
defer c.mu.Unlock()
sub := c.subs["1"]
if ls := len(sub.shadow); ls != expected {
t.Fatalf("Expected shadows to be %d, got %d", expected, ls)
}
checkFor(t, 3*time.Second, 15*time.Millisecond, func() error {
c.mu.Lock()
defer c.mu.Unlock()
sub := c.subs["1"]
if ls := len(sub.shadow); ls != expected {
return fmt.Errorf("Expected shadows to be %d, got %d", expected, ls)
}
return nil
})
}
// We created a SUB on foo which should create a shadow subscription.
checkShadow(1)
checkShadow(t, 1)
time.Sleep(1250 * time.Millisecond)
// Should have expired and been removed.
checkShadow(0)
checkShadow(t, 0)
}
func TestJWTAccountLimitsSubs(t *testing.T) {

View File

@@ -64,7 +64,7 @@ func runMonitorServerNoHTTPPort() *Server {
}
func resetPreviousHTTPConnections() {
http.DefaultTransport = &http.Transport{}
http.DefaultTransport.(*http.Transport).CloseIdleConnections()
}
func TestMyUptime(t *testing.T) {

View File

@@ -1163,7 +1163,7 @@ func TestConnErrorReports(t *testing.T) {
remoteURLs := RoutesFromStr("nats://127.0.0.1:1234")
opts = DefaultOptions()
opts.ConnectionErrorReportAttempts = 10
opts.ConnectionErrorReportAttempts = 3
opts.Cluster.Port = -1
opts.Routes = remoteURLs
opts.NoLog = false
@@ -1174,7 +1174,7 @@ func TestConnErrorReports(t *testing.T) {
defer s.Shutdown()
// Wait long enough for the number of recurring attempts to happen
time.Sleep(30 * routeConnectDelay)
time.Sleep(10 * routeConnectDelay)
s.Shutdown()
content, err := ioutil.ReadFile(log)
@@ -1198,18 +1198,18 @@ func TestConnErrorReports(t *testing.T) {
// We should find only [DBG] for second attempt...
checkContent(t, "[DBG] Error trying to connect to route", 2, true)
checkContent(t, "[ERR] Error trying to connect to route", 2, false)
// Then it should repeat at attempt 10
checkContent(t, "[DBG] Error trying to connect to route", 10, true)
checkContent(t, "[ERR] Error trying to connect to route", 10, true)
// Then it should repeat at attempt 3
checkContent(t, "[DBG] Error trying to connect to route", 3, true)
checkContent(t, "[ERR] Error trying to connect to route", 3, true)
// Only DBG again for next
checkContent(t, "[DBG] Error trying to connect to route", 11, true)
checkContent(t, "[ERR] Error trying to connect to route", 11, false)
// Then 20..
checkContent(t, "[DBG] Error trying to connect to route", 20, true)
checkContent(t, "[ERR] Error trying to connect to route", 20, true)
// for 21, only DBG
checkContent(t, "[DBG] Error trying to connect to route", 21, true)
checkContent(t, "[ERR] Error trying to connect to route", 21, false)
checkContent(t, "[DBG] Error trying to connect to route", 4, true)
checkContent(t, "[ERR] Error trying to connect to route", 4, false)
// Then 6..
checkContent(t, "[DBG] Error trying to connect to route", 6, true)
checkContent(t, "[ERR] Error trying to connect to route", 6, true)
// for 7, only DBG
checkContent(t, "[DBG] Error trying to connect to route", 7, true)
checkContent(t, "[ERR] Error trying to connect to route", 7, false)
os.Remove(log)
@@ -1222,7 +1222,7 @@ func TestConnErrorReports(t *testing.T) {
defer s.Shutdown()
// Wait long enough for the number of recurring attempts to happen
time.Sleep(30 * opts.LeafNode.ReconnectInterval)
time.Sleep(10 * opts.LeafNode.ReconnectInterval)
s.Shutdown()
content, err = ioutil.ReadFile(log)
@@ -1236,18 +1236,18 @@ func TestConnErrorReports(t *testing.T) {
// For second attempt, only debug
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 2, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 2, false)
// Then it should repeat at attempt 10
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 10, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 10, true)
// Then it should repeat at attempt 3
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 3, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 3, true)
// Next, only DBG
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 11, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 11, false)
// Then 20..
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 20, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 20, true)
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 4, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 4, false)
// Then 6..
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 6, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 6, true)
// Next only DBG...
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 21, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 21, false)
checkContent(t, "[DBG] Error trying to connect as leaf node to remote server", 7, true)
checkContent(t, "[ERR] Error trying to connect as leaf node to remote server", 7, false)
os.Remove(log)
@@ -1266,7 +1266,7 @@ func TestConnErrorReports(t *testing.T) {
defer s.Shutdown()
// Wait long enough for the number of recurring attempts to happen
time.Sleep(30 * gatewayConnectDelay)
time.Sleep(10 * gatewayConnectDelay)
s.Shutdown()
content, err = ioutil.ReadFile(log)
@@ -1287,27 +1287,27 @@ func TestConnErrorReports(t *testing.T) {
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 2, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 2, false)
// All for 10
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 10, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 10, true)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 10, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 10, true)
// All for 3
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 3, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 3, true)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 3, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 3, true)
// Next only DBG
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 11, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 11, false)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 11, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 11, false)
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 4, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 4, false)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 4, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 4, false)
// All for 10
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 20, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 20, true)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 20, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 20, true)
// All for 6
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 6, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 6, true)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 6, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 6, true)
// Nex, only DBG
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 21, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 21, false)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 21, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 21, false)
// Next, only DBG
checkContent(t, "[DBG] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 7, true)
checkContent(t, "[INF] Connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 7, false)
checkContent(t, "[DBG] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 7, true)
checkContent(t, "[ERR] Error connecting to explicit gateway \"B\" (127.0.0.1:1234) at 127.0.0.1:1234", 7, false)
}

View File

@@ -414,9 +414,9 @@ func TestGatewaySendAllSubs(t *testing.T) {
// Bombard B with messages on different subjects.
// TODO(ik): Adapt if/when we change the conditions for the
// switch.
for i := 0; i < 10001; i++ {
for i := 0; i < 1010; i++ {
gASend(fmt.Sprintf("RMSG $G foo.%d 2\r\nok\r\n", i))
if i <= 1000 {
if i < 1000 {
gAExpect(runsubRe)
}
}