diff --git a/server/auth_test.go b/server/auth_test.go index 28d6d753..145cab06 100644 --- a/server/auth_test.go +++ b/server/auth_test.go @@ -294,19 +294,26 @@ func TestUserConnectionDeadline(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) - nc, err := nats.Connect(s.ClientURL(), nats.UserInfo("valid", ""), nats.NoReconnect(), nats.ErrorHandler(func(nc *nats.Conn, _ *nats.Subscription, err error) { - dcerr = err - cancel() - })) + nc, err := nats.Connect( + s.ClientURL(), + nats.UserInfo("valid", _EMPTY_), + nats.NoReconnect(), + nats.ErrorHandler(func(nc *nats.Conn, _ *nats.Subscription, err error) { + dcerr = err + cancel() + })) if err != nil { t.Fatalf("Expected client to connect, got: %s", err) } <-ctx.Done() - if nc.IsConnected() { - t.Fatalf("Expected to be disconnected") - } + checkFor(t, 2*time.Second, 100*time.Millisecond, func() error { + if nc.IsConnected() { + return fmt.Errorf("Expected to be disconnected") + } + return nil + }) if dcerr == nil || dcerr.Error() != "nats: authentication expired" { t.Fatalf("Expected a auth expired error: got: %v", dcerr) diff --git a/server/events_test.go b/server/events_test.go index 61ce61b2..09c7ee3f 100644 --- a/server/events_test.go +++ b/server/events_test.go @@ -1268,7 +1268,7 @@ func TestAccountReqMonitoring(t *testing.T) { // query SUBSZ for account resp, err := ncSys.Request(subsz, nil, time.Second) require_NoError(t, err) - require_Contains(t, string(resp.Data), `"num_subscriptions":4,`) + require_Contains(t, string(resp.Data), `"num_subscriptions":5,`) // create a subscription sub, err := nc.Subscribe("foo", func(msg *nats.Msg) {}) require_NoError(t, err) @@ -1278,7 +1278,7 @@ func TestAccountReqMonitoring(t *testing.T) { // query SUBSZ for account resp, err = ncSys.Request(subsz, nil, time.Second) require_NoError(t, err) - require_Contains(t, string(resp.Data), `"num_subscriptions":5,`, `"subject":"foo"`) + require_Contains(t, string(resp.Data), `"num_subscriptions":6,`, `"subject":"foo"`) // query connections for account resp, err = ncSys.Request(connz, nil, time.Second) require_NoError(t, err) @@ -1418,7 +1418,7 @@ func TestAccountReqInfo(t *testing.T) { t.Fatalf("Unmarshalling failed: %v", err) } else if len(info.Exports) != 1 { t.Fatalf("Unexpected value: %v", info.Exports) - } else if len(info.Imports) != 3 { + } else if len(info.Imports) != 4 { t.Fatalf("Unexpected value: %+v", info.Imports) } else if info.Exports[0].Subject != "req.*" { t.Fatalf("Unexpected value: %v", info.Exports) @@ -1426,7 +1426,7 @@ func TestAccountReqInfo(t *testing.T) { t.Fatalf("Unexpected value: %v", info.Exports) } else if info.Exports[0].ResponseType != jwt.ResponseTypeSingleton { t.Fatalf("Unexpected value: %v", info.Exports) - } else if info.SubCnt != 3 { + } else if info.SubCnt != 4 { t.Fatalf("Unexpected value: %v", info.SubCnt) } else { checkCommon(&info, &srv, pub1, ajwt1) @@ -1439,7 +1439,7 @@ func TestAccountReqInfo(t *testing.T) { t.Fatalf("Unmarshalling failed: %v", err) } else if len(info.Exports) != 0 { t.Fatalf("Unexpected value: %v", info.Exports) - } else if len(info.Imports) != 4 { + } else if len(info.Imports) != 5 { t.Fatalf("Unexpected value: %+v", info.Imports) } // Here we need to find our import @@ -1457,7 +1457,7 @@ func TestAccountReqInfo(t *testing.T) { t.Fatalf("Unexpected value: %+v", si) } else if si.Account != pub1 { t.Fatalf("Unexpected value: %+v", si) - } else if info.SubCnt != 4 { + } else if info.SubCnt != 5 { t.Fatalf("Unexpected value: %+v", si) } else { checkCommon(&info, &srv, pub2, ajwt2) @@ -1664,7 +1664,7 @@ func TestSystemAccountWithGateways(t *testing.T) { // If this tests fails with wrong number after 10 seconds we may have // added a new inititial subscription for the eventing system. - checkExpectedSubs(t, 47, sa) + checkExpectedSubs(t, 50, sa) // Create a client on B and see if we receive the event urlb := fmt.Sprintf("nats://%s:%d", ob.Host, ob.Port) diff --git a/server/leafnode_test.go b/server/leafnode_test.go index bb81d85b..78a77a35 100644 --- a/server/leafnode_test.go +++ b/server/leafnode_test.go @@ -1319,7 +1319,7 @@ func TestLeafNodePermissions(t *testing.T) { // Create a sub on ">" on LN1 subAll := natsSubSync(t, nc1, ">") // this should be registered in LN2 (there is 1 sub for LN1 $LDS subject) + SYS IMPORTS - checkSubs(ln2.globalAccount(), 10) + checkSubs(ln2.globalAccount(), 12) // Check deny export clause from messages published from LN2 for _, test := range []struct { @@ -1346,7 +1346,7 @@ func TestLeafNodePermissions(t *testing.T) { subAll.Unsubscribe() // Goes down by 1. - checkSubs(ln2.globalAccount(), 9) + checkSubs(ln2.globalAccount(), 11) // We used to make sure we would not do subscriptions however that // was incorrect. We need to check publishes, not the subscriptions. @@ -1371,7 +1371,7 @@ func TestLeafNodePermissions(t *testing.T) { } { t.Run(test.name, func(t *testing.T) { sub := natsSubSync(t, nc2, test.subSubject) - checkSubs(ln2.globalAccount(), 10) + checkSubs(ln2.globalAccount(), 12) if !test.ok { nc1.Publish(test.pubSubject, []byte("msg")) @@ -1379,12 +1379,12 @@ func TestLeafNodePermissions(t *testing.T) { t.Fatalf("Did not expect to get the message") } } else { - checkSubs(ln1.globalAccount(), 9) + checkSubs(ln1.globalAccount(), 11) nc1.Publish(test.pubSubject, []byte("msg")) natsNexMsg(t, sub, time.Second) } sub.Unsubscribe() - checkSubs(ln1.globalAccount(), 8) + checkSubs(ln1.globalAccount(), 10) }) } } @@ -1505,8 +1505,8 @@ func TestLeafNodeExportPermissionsNotForSpecialSubs(t *testing.T) { // The deny is totally restrictive, but make sure that we still accept the $LDS, $GR and _GR_ go from LN1. checkFor(t, time.Second, 15*time.Millisecond, func() error { // We should have registered the 3 subs from the accepting leafnode. - if n := ln2.globalAccount().TotalSubs(); n != 8 { - return fmt.Errorf("Expected %d subs, got %v", 8, n) + if n := ln2.globalAccount().TotalSubs(); n != 9 { + return fmt.Errorf("Expected %d subs, got %v", 9, n) } return nil }) @@ -3474,8 +3474,8 @@ func TestLeafNodeRouteSubWithOrigin(t *testing.T) { r1.Shutdown() checkFor(t, time.Second, 15*time.Millisecond, func() error { acc := l2.GlobalAccount() - if n := acc.TotalSubs(); n != 4 { - return fmt.Errorf("Account %q should have 3 subs, got %v", acc.GetName(), n) + if n := acc.TotalSubs(); n != 5 { + return fmt.Errorf("Account %q should have 5 subs, got %v", acc.GetName(), n) } return nil }) diff --git a/server/monitor_test.go b/server/monitor_test.go index 0e666bb6..e0f5a97d 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -3914,8 +3914,8 @@ func TestMonitorLeafz(t *testing.T) { t.Fatalf("RTT not tracked?") } // LDS should be only one. - if ln.NumSubs != 4 || len(ln.Subs) != 4 { - t.Fatalf("Expected 3 subs, got %v (%v)", ln.NumSubs, ln.Subs) + if ln.NumSubs != 5 || len(ln.Subs) != 5 { + t.Fatalf("Expected 5 subs, got %v (%v)", ln.NumSubs, ln.Subs) } } } @@ -3933,7 +3933,7 @@ func TestMonitorAccountz(t *testing.T) { body = string(readBody(t, fmt.Sprintf("http://127.0.0.1:%d%s?acc=$SYS", s.MonitorAddr().Port, AccountzPath))) require_Contains(t, body, `"account_detail": {`) require_Contains(t, body, `"account_name": "$SYS",`) - require_Contains(t, body, `"subscriptions": 42,`) + require_Contains(t, body, `"subscriptions": 44,`) require_Contains(t, body, `"is_system": true,`) require_Contains(t, body, `"system_account": "$SYS"`) diff --git a/test/leafnode_test.go b/test/leafnode_test.go index abd84fd7..e81fddb8 100644 --- a/test/leafnode_test.go +++ b/test/leafnode_test.go @@ -199,7 +199,7 @@ func setupLeaf(t *testing.T, lc net.Conn, expectedSubs int) (sendFun, expectFun) send, expect := setupConn(t, lc) // A loop detection subscription is sent, so consume this here, along // with the ones that caller expect on setup. - expectNumberOfProtos(t, expect, lsubRe, expectedSubs, infoRe, pingRe) + expectNumberOfProtos(t, expect, lsubRe, expectedSubs, infoStartRe, pingRe) return send, expect } @@ -439,7 +439,7 @@ func TestLeafNodeAndRoutes(t *testing.T) { lc := createLeafConn(t, optsA.LeafNode.Host, optsA.LeafNode.Port) defer lc.Close() - leafSend, leafExpect := setupLeaf(t, lc, 5) + leafSend, leafExpect := setupLeaf(t, lc, 6) leafSend("PING\r\n") leafExpect(pongRe) @@ -833,7 +833,7 @@ func TestLeafNodeGatewaySendsSystemEvent(t *testing.T) { defer lc.Close() // This is for our global responses since we are setting up GWs above. - leafSend, leafExpect := setupLeaf(t, lc, 7) + leafSend, leafExpect := setupLeaf(t, lc, 8) leafSend("PING\r\n") leafExpect(pongRe) @@ -874,17 +874,18 @@ func TestLeafNodeGatewayInterestPropagation(t *testing.T) { lc := createLeafConn(t, opts.LeafNode.Host, opts.LeafNode.Port) defer lc.Close() _, leafExpect := setupConn(t, lc) - buf := leafExpect(infoRe) - buf = infoRe.ReplaceAll(buf, []byte(nil)) + buf := leafExpect(infoStartRe) + buf = infoStartRe.ReplaceAll(buf, []byte(nil)) + foundFoo := false - for count := 0; count != 9; { + for count := 0; count < 10; { // skip first time if we still have data (buf from above may already have some left) if count != 0 || len(buf) == 0 { buf = append(buf, leafExpect(anyRe)...) } count += len(lsubRe.FindAllSubmatch(buf, -1)) - if count > 9 { - t.Fatalf("Expected %v matches, got %v (buf=%s)", 8, count, buf) + if count > 10 { + t.Fatalf("Expected %v matches, got %v (buf=%s)", 10, count, buf) } if strings.Contains(string(buf), "foo") { foundFoo = true @@ -936,7 +937,7 @@ func TestLeafNodeWithRouteAndGateway(t *testing.T) { defer lc.Close() // This is for our global responses since we are setting up GWs above. - leafSend, leafExpect := setupLeaf(t, lc, 7) + leafSend, leafExpect := setupLeaf(t, lc, 8) leafSend("PING\r\n") leafExpect(pongRe) @@ -995,7 +996,7 @@ func TestLeafNodeWithGatewaysAndStaggeredStart(t *testing.T) { lc := createLeafConn(t, opts.LeafNode.Host, opts.LeafNode.Port) defer lc.Close() - leafSend, leafExpect := setupLeaf(t, lc, 7) + leafSend, leafExpect := setupLeaf(t, lc, 8) leafSend("PING\r\n") leafExpect(pongRe) @@ -1035,7 +1036,7 @@ func TestLeafNodeWithGatewaysServerRestart(t *testing.T) { lc := createLeafConn(t, opts.LeafNode.Host, opts.LeafNode.Port) defer lc.Close() - leafSend, leafExpect := setupLeaf(t, lc, 7) + leafSend, leafExpect := setupLeaf(t, lc, 8) leafSend("PING\r\n") leafExpect(pongRe) @@ -1069,7 +1070,7 @@ func TestLeafNodeWithGatewaysServerRestart(t *testing.T) { lc = createLeafConn(t, opts.LeafNode.Host, opts.LeafNode.Port) defer lc.Close() - _, leafExpect = setupLeaf(t, lc, 7) + _, leafExpect = setupLeaf(t, lc, 8) // Now wait on GW solicit to fire time.Sleep(500 * time.Millisecond) @@ -2063,7 +2064,7 @@ func TestLeafNodeExportImportComplexSetup(t *testing.T) { // Wait for the sub to propagate to s2. LDS + subject above. checkFor(t, 2*time.Second, 15*time.Millisecond, func() error { - if acc1.RoutedSubs() != 5 { + if acc1.RoutedSubs() != 6 { return fmt.Errorf("Still no routed subscription: %d", acc1.RoutedSubs()) } return nil @@ -2649,7 +2650,7 @@ func TestLeafNodeSwitchGatewayToInterestModeOnly(t *testing.T) { defer lc.Close() // This is for our global responses since we are setting up GWs above. - leafSend, leafExpect := setupLeaf(t, lc, 7) + leafSend, leafExpect := setupLeaf(t, lc, 8) leafSend("PING\r\n") leafExpect(pongRe) } diff --git a/test/test.go b/test/test.go index 8fe94b6a..b7342443 100644 --- a/test/test.go +++ b/test/test.go @@ -345,25 +345,26 @@ func sendProto(t tLogger, c net.Conn, op string) { } var ( - anyRe = regexp.MustCompile(`.*`) - infoRe = regexp.MustCompile(`INFO\s+([^\r\n]+)\r\n`) - pingRe = regexp.MustCompile(`^PING\r\n`) - pongRe = regexp.MustCompile(`^PONG\r\n`) - hmsgRe = regexp.MustCompile(`(?:(?:HMSG\s+([^\s]+)\s+([^\s]+)\s+(([^\s]+)[^\S\r\n]+)?(\d+)\s+(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) - msgRe = regexp.MustCompile(`(?:(?:MSG\s+([^\s]+)\s+([^\s]+)\s+(([^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) - rawMsgRe = regexp.MustCompile(`(?:(?:MSG\s+([^\s]+)\s+([^\s]+)\s+(([^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n(.*?)))`) - okRe = regexp.MustCompile(`\A\+OK\r\n`) - errRe = regexp.MustCompile(`\A\-ERR\s+([^\r\n]+)\r\n`) - connectRe = regexp.MustCompile(`CONNECT\s+([^\r\n]+)\r\n`) - rsubRe = regexp.MustCompile(`RS\+\s+([^\s]+)\s+([^\s]+)\s*([^\s]+)?\s*(\d+)?\r\n`) - runsubRe = regexp.MustCompile(`RS\-\s+([^\s]+)\s+([^\s]+)\s*([^\s]+)?\r\n`) - rmsgRe = regexp.MustCompile(`(?:(?:RMSG\s+([^\s]+)\s+([^\s]+)\s+(?:([|+]\s+([\w\s]+)|[^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) - asubRe = regexp.MustCompile(`A\+\s+([^\r\n]+)\r\n`) - aunsubRe = regexp.MustCompile(`A\-\s+([^\r\n]+)\r\n`) - lsubRe = regexp.MustCompile(`LS\+\s+([^\s]+)\s*([^\s]+)?\s*(\d+)?\r\n`) - lunsubRe = regexp.MustCompile(`LS\-\s+([^\s]+)\s*([^\s]+)?\r\n`) - lmsgRe = regexp.MustCompile(`(?:(?:LMSG\s+([^\s]+)\s+(?:([|+]\s+([\w\s]+)|[^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) - rlsubRe = regexp.MustCompile(`LS\+\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s*([^\s]+)?\s*(\d+)?\r\n`) + anyRe = regexp.MustCompile(`.*`) + infoRe = regexp.MustCompile(`INFO\s+([^\r\n]+)\r\n`) + infoStartRe = regexp.MustCompile(`^INFO\s+([^\r\n]+)\r\n`) + pingRe = regexp.MustCompile(`^PING\r\n`) + pongRe = regexp.MustCompile(`^PONG\r\n`) + hmsgRe = regexp.MustCompile(`(?:(?:HMSG\s+([^\s]+)\s+([^\s]+)\s+(([^\s]+)[^\S\r\n]+)?(\d+)\s+(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) + msgRe = regexp.MustCompile(`(?:(?:MSG\s+([^\s]+)\s+([^\s]+)\s+(([^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) + rawMsgRe = regexp.MustCompile(`(?:(?:MSG\s+([^\s]+)\s+([^\s]+)\s+(([^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n(.*?)))`) + okRe = regexp.MustCompile(`\A\+OK\r\n`) + errRe = regexp.MustCompile(`\A\-ERR\s+([^\r\n]+)\r\n`) + connectRe = regexp.MustCompile(`CONNECT\s+([^\r\n]+)\r\n`) + rsubRe = regexp.MustCompile(`RS\+\s+([^\s]+)\s+([^\s]+)\s*([^\s]+)?\s*(\d+)?\r\n`) + runsubRe = regexp.MustCompile(`RS\-\s+([^\s]+)\s+([^\s]+)\s*([^\s]+)?\r\n`) + rmsgRe = regexp.MustCompile(`(?:(?:RMSG\s+([^\s]+)\s+([^\s]+)\s+(?:([|+]\s+([\w\s]+)|[^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) + asubRe = regexp.MustCompile(`A\+\s+([^\r\n]+)\r\n`) + aunsubRe = regexp.MustCompile(`A\-\s+([^\r\n]+)\r\n`) + lsubRe = regexp.MustCompile(`LS\+\s+([^\s]+)\s*([^\s]+)?\s*(\d+)?\r\n`) + lunsubRe = regexp.MustCompile(`LS\-\s+([^\s]+)\s*([^\s]+)?\r\n`) + lmsgRe = regexp.MustCompile(`(?:(?:LMSG\s+([^\s]+)\s+(?:([|+]\s+([\w\s]+)|[^\s]+)[^\S\r\n]+)?(\d+)\s*\r\n([^\\r\\n]*?)\r\n)+?)`) + rlsubRe = regexp.MustCompile(`LS\+\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s*([^\s]+)?\s*(\d+)?\r\n`) ) const (