As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit b4277440 authored by Patrick Bajao's avatar Patrick Bajao
Browse files

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.
parent 75f18461
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -177,7 +177,7 @@ func TestCanceledContext(t *testing.T) {
cmd := &Command{
Config: &config.Config{GitlabUrl: url},
Args: &commandargs.Shell{GitlabKeyId: "wait_infinitely"},
ReadWriter: &readwriter.ReadWriter{Out: output, In: &bytes.Buffer{}},
ReadWriter: &readwriter.ReadWriter{Out: output, In: &blockingReader{}},
}
ctx, cancel := context.WithCancel(context.Background())
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment