|
|
|
|
@@ -1394,23 +1394,21 @@ func TestConnectErrorReports(t *testing.T) {
|
|
|
|
|
s = RunServer(opts)
|
|
|
|
|
defer s.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait long enough for the number of recurring attempts to happen
|
|
|
|
|
time.Sleep(50 * routeConnectDelay)
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
|
|
|
|
|
content, err := ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkContent := func(t *testing.T, txt string, attempt int, shouldBeThere bool) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s (attempt %d)", txt, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
t.Fatalf("Did not find expected log statement (%s) for attempt %d: %s", txt, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
t.Fatalf("Log statement (%s) for attempt %d should not be present: %s", txt, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
checkFor(t, 2*time.Second, 15*time.Millisecond, func() error {
|
|
|
|
|
content, err := ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s (attempt %d)", txt, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
return fmt.Errorf("Did not find expected log statement (%s) for attempt %d: %s", txt, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
return fmt.Errorf("Log statement (%s) for attempt %d should not be present: %s", txt, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type testConnect struct {
|
|
|
|
|
@@ -1433,6 +1431,7 @@ func TestConnectErrorReports(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
os.Remove(log)
|
|
|
|
|
|
|
|
|
|
// Now try with leaf nodes
|
|
|
|
|
@@ -1443,23 +1442,21 @@ func TestConnectErrorReports(t *testing.T) {
|
|
|
|
|
s = RunServer(opts)
|
|
|
|
|
defer s.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait long enough for the number of recurring attempts to happen
|
|
|
|
|
time.Sleep(50 * opts.LeafNode.ReconnectInterval)
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
|
|
|
|
|
content, err = ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkLeafContent := func(t *testing.T, txt, host string, attempt int, shouldBeThere bool) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s %q (attempt %d)", txt, host, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
t.Fatalf("Did not find expected log statement (%s %q) for attempt %d: %s", txt, host, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
t.Fatalf("Log statement (%s %q) for attempt %d should not be present: %s", txt, host, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
checkFor(t, 2*time.Second, 15*time.Millisecond, func() error {
|
|
|
|
|
content, err := ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s %q (attempt %d)", txt, host, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
return fmt.Errorf("Did not find expected log statement (%s %q) for attempt %d: %s", txt, host, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
return fmt.Errorf("Log statement (%s %q) for attempt %d should not be present: %s", txt, host, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, test := range []testConnect{
|
|
|
|
|
@@ -1477,6 +1474,7 @@ func TestConnectErrorReports(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
os.Remove(log)
|
|
|
|
|
|
|
|
|
|
// Now try with gateways
|
|
|
|
|
@@ -1493,15 +1491,6 @@ func TestConnectErrorReports(t *testing.T) {
|
|
|
|
|
s = RunServer(opts)
|
|
|
|
|
defer s.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait long enough for the number of recurring attempts to happen
|
|
|
|
|
time.Sleep(50 * gatewayConnectDelay)
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
|
|
|
|
|
content, err = ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, test := range []testConnect{
|
|
|
|
|
{"gateway_attempt_1", 1, true},
|
|
|
|
|
{"gateway_attempt_2", 2, false},
|
|
|
|
|
@@ -1568,23 +1557,24 @@ func TestReconnectErrorReports(t *testing.T) {
|
|
|
|
|
// Now shutdown the server s connected to.
|
|
|
|
|
cs.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait long enough for the number of recurring attempts to happen
|
|
|
|
|
time.Sleep(DEFAULT_ROUTE_RECONNECT + 50*routeConnectDelay)
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
|
|
|
|
|
content, err := ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
// Specifically for route test, wait at least reconnect interval before checking logs
|
|
|
|
|
time.Sleep(DEFAULT_ROUTE_RECONNECT)
|
|
|
|
|
|
|
|
|
|
checkContent := func(t *testing.T, txt string, attempt int, shouldBeThere bool) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s (attempt %d)", txt, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
t.Fatalf("Did not find expected log statement (%s) for attempt %d: %s", txt, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
t.Fatalf("Log statement (%s) for attempt %d should not be present: %s", txt, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
checkFor(t, 2*time.Second, 15*time.Millisecond, func() error {
|
|
|
|
|
content, err := ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s (attempt %d)", txt, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
return fmt.Errorf("Did not find expected log statement (%s) for attempt %d: %s", txt, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
return fmt.Errorf("Log statement (%s) for attempt %d should not be present: %s", txt, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type testConnect struct {
|
|
|
|
|
@@ -1607,6 +1597,7 @@ func TestReconnectErrorReports(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
os.Remove(log)
|
|
|
|
|
|
|
|
|
|
// Now try with leaf nodes
|
|
|
|
|
@@ -1625,33 +1616,26 @@ func TestReconnectErrorReports(t *testing.T) {
|
|
|
|
|
s = RunServer(opts)
|
|
|
|
|
defer s.Shutdown()
|
|
|
|
|
|
|
|
|
|
checkFor(t, 3*time.Second, 10*time.Millisecond, func() error {
|
|
|
|
|
if nln := s.NumLeafNodes(); nln != 1 {
|
|
|
|
|
return fmt.Errorf("Number of leaf nodes is %d", nln)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
checkLeafNodeConnected(t, s)
|
|
|
|
|
|
|
|
|
|
// Now shutdown the server s is connected to
|
|
|
|
|
cs.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait long enough for the number of recurring attempts to happen
|
|
|
|
|
time.Sleep(50 * opts.LeafNode.ReconnectInterval)
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
|
|
|
|
|
content, err = ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkLeafContent := func(t *testing.T, txt, host string, attempt int, shouldBeThere bool) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s %q (attempt %d)", txt, host, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
t.Fatalf("Did not find expected log statement (%s %q) for attempt %d: %s", txt, host, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
t.Fatalf("Log statement (%s %q) for attempt %d should not be present: %s", txt, host, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
checkFor(t, 2*time.Second, 15*time.Millisecond, func() error {
|
|
|
|
|
content, err := ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
present := bytes.Contains(content, []byte(fmt.Sprintf("%s %q (attempt %d)", txt, host, attempt)))
|
|
|
|
|
if shouldBeThere && !present {
|
|
|
|
|
return fmt.Errorf("Did not find expected log statement (%s %q) for attempt %d: %s", txt, host, attempt, content)
|
|
|
|
|
} else if !shouldBeThere && present {
|
|
|
|
|
return fmt.Errorf("Log statement (%s %q) for attempt %d should not be present: %s", txt, host, attempt, content)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, test := range []testConnect{
|
|
|
|
|
@@ -1669,6 +1653,7 @@ func TestReconnectErrorReports(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
os.Remove(log)
|
|
|
|
|
|
|
|
|
|
// Now try with gateways
|
|
|
|
|
@@ -1698,15 +1683,6 @@ func TestReconnectErrorReports(t *testing.T) {
|
|
|
|
|
// Now stop server s is connecting to
|
|
|
|
|
cs.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait long enough for the number of recurring attempts to happen
|
|
|
|
|
time.Sleep(50 * gatewayConnectDelay)
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
|
|
|
|
|
content, err = ioutil.ReadFile(log)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error reading log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connTxt := fmt.Sprintf("Connecting to explicit gateway \"B\" (127.0.0.1:%d) at 127.0.0.1:%d", remoteGWPort, remoteGWPort)
|
|
|
|
|
dbgConnTxt := fmt.Sprintf("[DBG] %s", connTxt)
|
|
|
|
|
infConnTxt := fmt.Sprintf("[INF] %s", connTxt)
|
|
|
|
|
|