-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add simple external test covering cache verification #118
Conversation
I should add a small sub test to ensure a second usage of the layer uses the cached file this time. |
test/external/external_test.go
Outdated
define.When(`^removing relok8s-save-cache$`, func() { | ||
err := os.RemoveAll(saveCacheFolder()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is just a cleanup step, you can add a second func()
that runs after all of the regular steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is not really a clean up. I will remove this to clear relok8s-save-cache
because this is a pre-step before testing the cache. This ensures the first run is not using cached content, yet the cached content gets populated:
steps.When("clear relok8s-save-cache")
steps.When(fmt.Sprintf("running relok8s chart move -y ../fixtures/testchart --image-patterns ../fixtures/testchart.images.yaml --to-intermediate-bundle %s/testchart-intermediate.tar", tmpDir))
...
steps.Then("relok8s-save-cache contains expected layer")
Still, I did not know the cleanup trick for goerkin
, and it might be useful elsewhere.
Abandoned in favor of #119 |
#119 got rejected so we resume this again to have test coverage of the caching support. |
aac8f05
to
55ee8d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't update the headers of files that have not been updated.
did you get a error when running the linter locally or in the CI? note that I changed the github action to only take into account what has changed, locally it's by default like that.
Signed-off-by: Jose Luis Vazquez Gonzalez <[email protected]>
Signed-off-by: Jose Luis Vazquez Gonzalez <[email protected]>
Signed-off-by: Jose Luis Vazquez Gonzalez <[email protected]>
55ee8d8
to
504785c
Compare
Done, I have removed the header renames also from this PR. I updated the header only on the file touched here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -19,6 +19,15 @@ import ( | |||
. "github.com/onsi/gomega/gbytes" | |||
) | |||
|
|||
func saveCacheFolder() string { | |||
return filepath.Join(os.TempDir(), "relok8s-save-cache") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually deleting the cache that's being used by relok8s itself right? I don't like that running a test has the side-effect of deleting the actual tooling cache.
Could we instead run these tests pointing to an unique, per-test cache path? This might require adding support for our tool via ENV variable or flag to point to the cache directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not want to add more code to be able to test, we already abandoned a change for that.
Maybe I can remove the specific layer instead for the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, don't worry about it, we can live with that side-effect I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/external/external_test.go
Outdated
modtime := info.ModTime() | ||
steps.When(fmt.Sprintf("running relok8s chart move -y ../fixtures/testchart --image-patterns ../fixtures/testchart.images.yaml --to-intermediate-bundle %s/testchart-intermediate-2.tar", tmpDir)) | ||
steps.And("the move is computed") | ||
steps.Then("the command says it will archive the chart") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there much value on again checking the output of the command? Could we just check on the second run that it does not expose any error and that the layer is there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/external/external_test.go
Outdated
info, err = os.Stat(expectedLayerFile()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(info.ModTime()).To(Equal(modtime)) | ||
Expect(secondSaveDuration).To(BeNumerically("<", firstSaveDuration)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case can be brittle, what if extracting the file from local takes more than the network speed? It should not be the case in general but you are adding a dependency here to the underlying system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could remove this, checking the file mod time did not change means the layer was not overwritten and we can kind of assume it was reused by the cache.
Speaking of brittle tests, while I have not seen this one fail yet, I keep on seeing that unit test fail often:
--- FAIL: TestGroupChangesByChart (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
And that is on top of the harbor issue that fails some external tests sometimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timing checks removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--- FAIL: TestGroupChangesByChart (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
yep, i have it on my plate to take a look at it. I looked into it the other day but didn't manage to reproduce it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very weird indeed, it happened a few times to me for a little while, then did not happen again for some time. It looks like some kind of race condition somewhere.
Signed-off-by: Jose Luis Vazquez Gonzalez <[email protected]>
Signed-off-by: Jose Luis Vazquez Gonzalez <[email protected]>
Signed-off-by: Jose Luis Vazquez Gonzalez <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
define.Then(`^remove the archive folder at testchart-intermediate.tar$`, func() { | ||
err := os.Remove("testchart-intermediate.tar") | ||
define.When(`^clear relok8s-save-cache expected layer$`, func() { | ||
err := os.RemoveAll(expectedLayerFile()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks!
Signed-off-by: Jose Luis Vazquez Gonzalez [email protected]
This is the simplest way I can think of we ensure that, at the very least, if the cache stops working as expected we will notice in our testing. Deeper testing would be a lot more costly in time to what I can invest right now.