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

Add simple external test covering cache verification #118

Merged
merged 6 commits into from
Jan 12, 2022
Merged

Conversation

josvazg
Copy link
Contributor

@josvazg josvazg commented Dec 14, 2021

Signed-off-by: Jose Luis Vazquez Gonzalez josvaz@vmware.com

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.

@josvazg josvazg self-assigned this Dec 14, 2021
@josvazg
Copy link
Contributor Author

josvazg commented Dec 15, 2021

I should add a small sub test to ensure a second usage of the layer uses the cached file this time.

Comment on lines 266 to 306
define.When(`^removing relok8s-save-cache$`, func() {
err := os.RemoveAll(saveCacheFolder())
Expect(err).ToNot(HaveOccurred())
})
Copy link
Contributor

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.

http://www.bunniesandbeatings.com/goerkin/#cleanup-steps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Contributor Author

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.

@josvazg
Copy link
Contributor Author

josvazg commented Dec 16, 2021

Abandoned in favor of #119

@josvazg josvazg closed this Dec 16, 2021
@josvazg josvazg reopened this Jan 10, 2022
@josvazg
Copy link
Contributor Author

josvazg commented Jan 10, 2022

#119 got rejected so we resume this again to have test coverage of the caching support.

Copy link
Contributor

@migmartri migmartri left a 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.

Jose Luis Vazquez Gonzalez added 3 commits January 10, 2022 16:25
Signed-off-by: Jose Luis Vazquez Gonzalez <josvaz@vmware.com>
Signed-off-by: Jose Luis Vazquez Gonzalez <josvaz@vmware.com>
Signed-off-by: Jose Luis Vazquez Gonzalez <josvaz@vmware.com>
@josvazg
Copy link
Contributor Author

josvazg commented Jan 10, 2022

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.

Done, I have removed the header renames also from this PR. I updated the header only on the file touched here.

Copy link
Contributor

@migmartri migmartri left a 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")
Copy link
Contributor

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.

Copy link
Contributor Author

@josvazg josvazg Jan 11, 2022

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.

Copy link
Contributor

@migmartri migmartri Jan 11, 2022

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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")
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

info, err = os.Stat(expectedLayerFile())
Expect(err).ToNot(HaveOccurred())
Expect(info.ModTime()).To(Equal(modtime))
Expect(secondSaveDuration).To(BeNumerically("<", firstSaveDuration))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

timing checks removed

Copy link
Contributor

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

Copy link
Contributor Author

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.

Jose Luis Vazquez Gonzalez added 3 commits January 11, 2022 16:43
Signed-off-by: Jose Luis Vazquez Gonzalez <josvaz@vmware.com>
Signed-off-by: Jose Luis Vazquez Gonzalez <josvaz@vmware.com>
Signed-off-by: Jose Luis Vazquez Gonzalez <josvaz@vmware.com>
Copy link
Contributor

@migmartri migmartri left a 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())
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, thanks!

@josvazg josvazg merged commit f519eb3 into main Jan 12, 2022
@migmartri migmartri deleted the test-save-cache branch January 12, 2022 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants