Repository navigation
baggageclaim: regression tests for windows - #826
aliculPix4D wants to merge 1 commit into
Conversation
|
@marco-m-pix4d @odormond I opened this as a draft because I would like to collect your feedback while I am on training, so I can continue working on Concourse test tomorrow. |
| }, | ||
| } | ||
|
|
||
| request, _ := http.NewRequest("PUT", fmt.Sprintf("/volumes/%s/stream-in?path=%s", myVolume.Handle, "dest-path"), buildGzipArchive(files)) |
There was a problem hiding this comment.
Not sure I would bother with formatting the path instead of just inlining it....
| request, _ := http.NewRequest("PUT", fmt.Sprintf("/volumes/%s/stream-in?path=%s", myVolume.Handle, "dest-path"), buildGzipArchive(files)) | |
| request, _ := http.NewRequest("PUT", fmt.Sprintf("/volumes/%s/stream-in?path=dest-path", myVolume.Handle), buildGzipArchive(files)) |
There was a problem hiding this comment.
Valid comment. My only excuse: all tests above are written in the same manner. I copy pasted 😳
L314: request, _ := http.NewRequest("PUT", fmt.Sprintf("/volumes/%s/stream-in?limit=0.000009&path=%s", myVolume.Handle, "dest-path"), tgzBuffer)
There was a problem hiding this comment.
If the surrounding code is written like this, then we need uniformity.
This code will be contributed upstream, correct ? Then maybe we can put also this fix in the PR that adds the missing assert on the error for NewRequest (on separate commit) and propose that PR also upstream ?
Another option is, in this case (not the missing assert) to "live with it", uniformity is important.
I don't have a strong opinion. The inlined version seems clearer.
| Expect(recorder.Code).To(Equal(400)) | ||
|
|
||
| escapingLinkPath := filepath.Join(volumeDir, "live", myVolume.Handle, "volume", "dest-path", "escaping-link") | ||
| Expect(escapingLinkPath).ToNot(BeAnExistingFile()) |
There was a problem hiding this comment.
You mentioned that 1 and then 2 tests were failing at various stage but without telling us which of the 3 failed (or I need more coffee), so I'm wondering if that one happened to pass in all cases which could be the case if it doesn't follow the symlink to check for existence. I think in most languages the default is too follow symlinks in such cases but I'm double checking. :-)
There was a problem hiding this comment.
On a similar vein, we need to be sure that ALL the tests that are being added here were actually failing at a certain point. Otherwise it is unclear what we are asserting here.
If now it is "too late" (that is: some tests being added here are regression tests for fixes that happened in previous commits), then we can still get at least a feeling that we are asserting the correct things by looking at the increased code coverage ?
There was a problem hiding this comment.
I didn't explain this part very well in PR description. I will write a detailed report, but I am actually very proud of this part. I run the same tests in different points in time on Vagrant Windows VM to confirm these new tests, catch everything we require.
Conclusion: if these tests existed before, the PRs that introduced each of the issues would never pass the status checks.
There was a problem hiding this comment.
Here is my summary:
Note before reading: please give special attention to exercise 3 example. It explains one super important thing that is easily missed. It explains why it is not enough in tests to assert on status code from the Baggageclaim Server and why it is IMPERATIVE to try to read the symlink file
I added 3 tests:
When the tar stream contains symlinks
- streams in a relative file symlink
- streams in a relative directory symlink
- rejects a symlink that escapes the destination (runs only on Windows; symlink breakout protection is only reliably exercised on Windows). Basically, here we should have the BreakoutError
Note: after I checkout the wanted commit in history, I just applied my git patch that adds only these 3 new tests; no other changes were done to the code or tests.
These are the exercises I did:
1st exercise: checkout to commit just BEFORE: concourse#9486 Basically, before any changes to this code path... when streaming was working no matter the symlinks.
Expectation: tests 1 and 2 will pass; streaming was always working; test 3 will fail because no one ever checked if sylink tries to escape the destination.
Result: Exactly, as I described in expectation. Basically, this is the behaviour of any Concourse version before v8.2
2nd exercise: checkout to commit just AFTER: concourse#9486
Expectation: tests 1 and 2 will fail with {"error":"failed to stream in to volume"}; streaming is now broken; test 3 will pass because after the PR we get BreakoutError in those situations.
Result: Exactly, as I described in expectation. This is the behaviour from v8.2 to v8.2.4.
At this point, streaming to Windows was broken (basically any valid symlink still contained in the volume we are streaming was breaking it) so we opened the issue: concourse#9597 which promted the PR concourse#9601 that introduces the os.Root.
3rd exercise: checkout to commit just AFTER os.Root was introduced: concourse#9601
Expectation: tests 1 and 2 will still fail, but with different errors on Windows 2019 and 2025; streaming is still broken; test 3 will still pass. Hence, it is imperative that we test on both Windows OS versions. Furthermore, on Windows 2025, streaming succeeds, but the created symlinks are broken. On Windows 2019 the streaming will fail due to robocopy. This is why it is also imperative that in the tests I try to read the file on the filesystem and not just look at the response status code from Baggageclaim server.
On Windows 2025:
This will pass: Expect(recorder.Code).To(Equal(204), "expected stream-in to succeed, got: %s", recorder.Body.String()) in both tests 1 and 2.
But this contents, err := os.ReadFile(symlinkedFile); Expect(err).NotTo(HaveOccurred()) will fail when trying to open the file/directory
Op: "open",
Err: <syscall.Errno>0x7b
On Windows 2019 I expect test 1 to fail when trying to open the file, same as on Windows 2025. On the other hand, test 2, I expect it to fail with: {"error":"failed to stream in to volume"} because the old version of robocopy will not work with directory symlinks.
Result: Almost exactly, as I described in expectation. I still need to test on Windows 2019. I only had 2025 Vagrant VM. This is the behaviour in v8.2.4. This is fixed on upstream master and on v8.2.4+pix4d.1
This prompted us to open: concourse#9609 and the famous Go Symlink issue I reported: golang/go#80073
4th exercise: run the CI on the feature branch of the PR itself: #826
All tests are passing since master contains all the required fixes.
There was a problem hiding this comment.
Note one more thing... If I had to describe what this PR does in a single sentence, I would say:
- This PR extends the existing baggageclaim api test coverage to cover volumes containing symlinks.
On the other hand, while I am happy that these tests really cover all issues we have recently encountered, it feels a bit unnatural that I add these symlink tests here.
A "perfect" place for these tests is go-archive package. I will certainly do that in next PR, so we will have a bit of overlap with these tests. I prefer this overlap, because baggageclaim tests are the only place we can really detec all of the failures. e.g. it would be impossible to write a test in go-archive that would detect the windows 2019 robocopy failure with directory symlinks.
| }, | ||
| } | ||
|
|
||
| request, _ := http.NewRequest("PUT", fmt.Sprintf("/volumes/%s/stream-in?path=%s", myVolume.Handle, "dest-path"), buildGzipArchive(files)) |
There was a problem hiding this comment.
NewRequest wants an URL, here we are passing an absolute path (missing scheme and host) ?
There was a problem hiding this comment.
Valid comments. My only excuse: all tests above are written in the same manner. I copy pasted 😳
What do you propose? Another cleanup PR to address this first? and then do the correct thing also here?
There was a problem hiding this comment.
Ah, cleanup PR to only add the missing assert on the error from http.NewRequest ?
Good idea indeed. Let's start from there, thanks.
| src, err := files.TarGZStream() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| buf := new(bytes.Buffer) |
There was a problem hiding this comment.
Looking more into the code, it seems it can be simplified. Why are we introducing a buffer to copy into it from a io.Reader ? that is already the correct type. We already have everything we need. Consider:
func (files Archive) TarGZStream() (io.Reader, error)
func NewRequest(method, url string, body io.Reader) (*Request, error)
so:
buildGzipArchive := func(files archivetest.Archive) io.Reader {
src, err := files.TarGZStream()
Expect(err).NotTo(HaveOccurred())
return src
}
:-)
|
Closing also this one. It will be replaced with something similar to: https://github.com/Pix4D/concourse/tree/pci-4898-goarchive-regression-tests since adding test in go-archive are a much better fit. |
baggageclaim: regression tests for Windows
It contains 3 new tests.
Only a draft to collect feedback.
Note that I run these tests locally in Vagrant VM for multiple commits
2 failing tests AS EXPECTED. This was the reason we opened: Windows volume streaming still broken for intra-repo symlinks due to
os.Root.Symlinkpath separator bug (Go #80073) concourse/concourse#9609