Skip to content

Commit b427744

Browse files
author
Patrick Bajao
committed
Use blocking reader to fix race in test
The `TestCanceledContext` test in `twofactorverify_test.go` tests the scenario wherein the request context gets canceled in the middle of the request. A race can occur though when the input gets read before the context is canceled which can result to a different error: instead of having the context canceled, the OTP will be blank. To fix it, we use a blocking reader as input to simulate "waiting for input" scenario. This way, reading the input will never be finished and the context cancelation can be done appropriately.
1 parent 75f1846 commit b427744

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

internal/command/twofactorverify/twofactorverify_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func TestCanceledContext(t *testing.T) {
177177
cmd := &Command{
178178
Config: &config.Config{GitlabUrl: url},
179179
Args: &commandargs.Shell{GitlabKeyId: "wait_infinitely"},
180-
ReadWriter: &readwriter.ReadWriter{Out: output, In: &bytes.Buffer{}},
180+
ReadWriter: &readwriter.ReadWriter{Out: output, In: &blockingReader{}},
181181
}
182182

183183
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)