summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2020-05-11 22:02:58 -0700
committerStan Hu <stanhu@gmail.com>2020-05-11 22:31:13 -0700
commit0372634076cdfd7cda740cd040e16e629ea662e4 (patch)
tree3b8c76cf68dcb9fa1c16d3aa370d0692a0800136 /client
parent940aa912784b2e99d6f2a767f13bd013a62c94f8 (diff)
downloadgitlab-shell-0372634076cdfd7cda740cd040e16e629ea662e4.tar.gz
Fix race conditions with logrus testingsh-fix-logrus-race
logrus fires a Goroutine to write logs, so the tests could fail if they checked the event queue before the logrus have fired. Since there isn't an easy way to flush all outstanding hooks, we just retry every 100 ms for up to a second for log to arrive in the queue. Closes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/450
Diffstat (limited to 'client')
-rw-r--r--client/client_test.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/client/client_test.go b/client/client_test.go
index 5e852dc..5c5fda8 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -123,6 +123,7 @@ func testSuccessfulGet(t *testing.T, client *GitlabNetClient) {
assert.NoError(t, err)
assert.Equal(t, string(responseBody), "Hello")
+ require.True(t, testhelper.WaitForLogEvent(hook))
entries := hook.AllEntries()
assert.Equal(t, 1, len(entries))
assert.Equal(t, logrus.InfoLevel, entries[0].Level)
@@ -147,6 +148,7 @@ func testSuccessfulPost(t *testing.T, client *GitlabNetClient) {
assert.NoError(t, err)
assert.Equal(t, "Echo: {\"key\":\"value\"}", string(responseBody))
+ require.True(t, testhelper.WaitForLogEvent(hook))
entries := hook.AllEntries()
assert.Equal(t, 1, len(entries))
assert.Equal(t, logrus.InfoLevel, entries[0].Level)
@@ -163,6 +165,7 @@ func testMissing(t *testing.T, client *GitlabNetClient) {
assert.EqualError(t, err, "Internal API error (404)")
assert.Nil(t, response)
+ require.True(t, testhelper.WaitForLogEvent(hook))
entries := hook.AllEntries()
assert.Equal(t, 1, len(entries))
assert.Equal(t, logrus.InfoLevel, entries[0].Level)
@@ -177,6 +180,7 @@ func testMissing(t *testing.T, client *GitlabNetClient) {
assert.EqualError(t, err, "Internal API error (404)")
assert.Nil(t, response)
+ require.True(t, testhelper.WaitForLogEvent(hook))
entries := hook.AllEntries()
assert.Equal(t, 1, len(entries))
assert.Equal(t, logrus.InfoLevel, entries[0].Level)
@@ -208,6 +212,7 @@ func testBrokenRequest(t *testing.T, client *GitlabNetClient) {
assert.EqualError(t, err, "Internal API unreachable")
assert.Nil(t, response)
+ require.True(t, testhelper.WaitForLogEvent(hook))
entries := hook.AllEntries()
assert.Equal(t, 1, len(entries))
assert.Equal(t, logrus.InfoLevel, entries[0].Level)
@@ -223,6 +228,7 @@ func testBrokenRequest(t *testing.T, client *GitlabNetClient) {
assert.EqualError(t, err, "Internal API unreachable")
assert.Nil(t, response)
+ require.True(t, testhelper.WaitForLogEvent(hook))
entries := hook.AllEntries()
assert.Equal(t, 1, len(entries))
assert.Equal(t, logrus.InfoLevel, entries[0].Level)