Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent real requests to the cloud during integration tests #2802

Merged
merged 2 commits into from
Dec 6, 2022

Conversation

na--
Copy link
Member

@na-- na-- commented Dec 5, 2022

These integration tests might have been a little too real... 😅

The first commit masks a data race around stdout (only until #2800 is merged) and a flaky check. The second commit ensures integration tests don't make usage report requests and adds a check to hopefully prevent a similar mistake in the future.

@na-- na-- added this to the v0.42.0 milestone Dec 5, 2022
@na-- na-- requested review from oleiade, imiric and codebien and removed request for mstoykov December 5, 2022 21:28
@na-- na-- force-pushed the prevent-real-network-requests-in-tests branch from 4820177 to f77f8e4 Compare December 5, 2022 21:57
@codecov-commenter
Copy link

Codecov Report

Merging #2802 (4820177) into master (47ab3de) will decrease coverage by 0.22%.
The diff coverage is n/a.

❗ Current head 4820177 differs from pull request most recent head f77f8e4. Consider uploading reports for the commit f77f8e4 to get more accurate results

@@            Coverage Diff             @@
##           master    #2802      +/-   ##
==========================================
- Coverage   76.21%   75.99%   -0.23%     
==========================================
  Files         210      208       -2     
  Lines       16435    16430       -5     
==========================================
- Hits        12526    12486      -40     
- Misses       3146     3176      +30     
- Partials      763      768       +5     
Flag Coverage Δ
ubuntu 75.99% <ø> (-0.10%) ⬇️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
loader/filesystems.go 60.00% <0.00%> (-40.00%) ⬇️
js/common/initenv.go 66.66% <0.00%> (-33.34%) ⬇️
cmd/run.go 70.25% <0.00%> (-14.36%) ⬇️
api/v1/metric.go 54.54% <0.00%> (-13.64%) ⬇️
lib/netext/httpext/error_codes.go 94.52% <0.00%> (-2.74%) ⬇️
output/influxdb/config.go 48.03% <0.00%> (-1.97%) ⬇️
js/initcontext.go 86.61% <0.00%> (-1.58%) ⬇️
core/local/local.go 90.15% <0.00%> (-1.14%) ⬇️
lib/netext/httpext/error_codes_syscall_windows.go
cmd/ui_windows.go
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

"reports.k6.io": true,
},
}
http.DefaultTransport = bt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is not mandatory, but should we do a clean-up after the test run? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I can add cleanup in a defer, but there is literally nothing after TestMain, the test exits. On the flip side, this is why we can also detect leaked goroutines in #2803

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know. I was saying that http.DefaultTransport is a global package variable, and it's kind of the best practice to revert its state after the test run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I agree, but IIRC, Go compiles and tests different packages in isolation, so it shouldn't matter. But even if it didn't, I'd argue it's probably better to have this http.DefaultTransport for as many tests as possible, just in case. To intentionally not revert it back.

There is no way normal k6 behavior will be affected, only tests, and it will either break a problematic test or do nothing, so no downsides. I even wondered if I shouldn't also os.Setenv() a real HTTP_PROXY environment variable and implement a small blocking proxy, just in case some part of cmd/ uses a custom http.RoundTripper (that doesn't rely on http.DefaultTransport) in the future, but decided that might be a bit too far to go and not worth it just for a bit of extra assurance 😅

@na-- na-- merged commit 1b9c5fa into master Dec 6, 2022
@na-- na-- deleted the prevent-real-network-requests-in-tests branch December 6, 2022 08:29
@na-- na-- added the tests label Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants