Merge pull request #1501 from nats-io/fix_test

Fixed some flappers
This commit is contained in:
Ivan Kozlovic
2020-07-03 11:47:58 -06:00
committed by GitHub
2 changed files with 16 additions and 12 deletions

View File

@@ -185,12 +185,14 @@ func TestAsyncClientWithRunningServer(t *testing.T) {
defer c.close()
buf := make([]byte, 1000000)
n := runtime.Stack(buf, true)
writeLoopTxt := fmt.Sprintf("writeLoop(%p)", c.client)
if count := strings.Count(string(buf[:n]), writeLoopTxt); count != 1 {
t.Fatalf("writeLoop for client started more than once: %v", count)
}
checkFor(t, time.Second, 15*time.Millisecond, func() error {
n := runtime.Stack(buf, true)
if count := strings.Count(string(buf[:n]), writeLoopTxt); count != 1 {
return fmt.Errorf("writeLoop for client should have been started only once: %v", count)
}
return nil
})
}
func TestClientCreateAndInfo(t *testing.T) {

View File

@@ -401,16 +401,18 @@ func TestClientAdvertiseErrorOnStartup(t *testing.T) {
opts.ClientAdvertise = "addr:::123"
s := New(opts)
defer s.Shutdown()
dl := &DummyLogger{}
s.SetLogger(dl, false, false)
l := &captureFatalLogger{fatalCh: make(chan string, 1)}
s.SetLogger(l, false, false)
// Expect this to return due to failure
s.Start()
dl.Lock()
msg := dl.msg
dl.Unlock()
if !strings.Contains(msg, "ClientAdvertise") {
t.Fatalf("Unexpected error: %v", msg)
select {
case msg := <-l.fatalCh:
if !strings.Contains(msg, "ClientAdvertise") {
t.Fatalf("Unexpected error: %v", msg)
}
case <-time.After(time.Second):
t.Fatalf("Should have failed to start")
}
}