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

Separate out promotion tests #204

Merged
merged 3 commits into from
Nov 20, 2023
Merged

Separate out promotion tests #204

merged 3 commits into from
Nov 20, 2023

Conversation

squaremo
Copy link
Contributor

@squaremo squaremo commented Nov 6, 2023

This isolates the tests more, so they can be run selectively, and so they can use their own setup.

As a side issue: we decided earlier that replacing the whole set of strategies broke encapsulation too much; but, I think it may be the simplest way to make the test repeatable. Otherwise, the test can't be run with --count > 1. The dummy strategy is added each time, and refers to out-of-date app objects in its lexical closure. I have adjusted this.

And as a diversion: the tests in controller_remote_test.go had an unreliable assumption, which I've fixed here because this is the PR where it was causing test failures most annoyingly.

This isolates the tests more, so they can be run selectively, and so
they can use their own setup.

Signed-off-by: Michael Bridgen <[email protected]>
These conditions ...

 - the pipeline reconciler is constructed in TestMain;
 - the test setup appends the mock strategy to the reconciler's
   strategies;
 - the mock strategy operates on values in its closure;
 - the first strategy answering `true` to Handle(...) will be used;

... all together mean that when you run the test case more than
once, it will end up running the mock strategy on apps that aren't
used any more.

We decided earlier that replacing the whole set of strategies broke
encapsulation too much; but, I think it may be the simplest way to
make the test repeatable.

These are alternatives I considered:

 - construct the reconciler anew for each test case (drags in the
   manager, then other things ...);

 - have a `Reset` method for the strategies (I don't like exporting
   methods just for testing);

 - refer to the app values indirectly, e.g., by having the mock
   strategy refer to a func which is re-assigned, rather than inlining
   it (would have to ensure the mock is installed once, but the func
   is reassigned -- awkward)

Signed-off-by: Michael Bridgen <[email protected]>
The remote target tests check that a target app is marked as unready
with an error of "not found" if it doesn't exist. But, running from
scratch, first the target will be unready because the cache for that
cluster has not synced yet, _then_ it will be unready because it's not
found. When the tests are run locally, it goes through that first
state fast enough that you probably wouldn't notice it; but in hosted
test runs (i.e., in GitHub Actions), running a test env for the remote
server is taxing enough that the flake becomes observable.

Thus: use `Eventually` here to check that it reaches that state,
rather than asserting it straight away.

Signed-off-by: Michael Bridgen <[email protected]>
Copy link
Collaborator

@yiannistri yiannistri left a comment

Choose a reason for hiding this comment

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

Out of interest, do we have a make target that we can use to run each of these in isolation? In other words, now that we've separated them, how does an engineer run them separately?

@squaremo squaremo merged commit e755cd2 into main Nov 20, 2023
6 checks passed
@squaremo squaremo deleted the separate-tests branch November 20, 2023 15:19
@squaremo
Copy link
Contributor Author

do we have a make target that we can use to run each of these in isolation? In other words, now that we've separated them, how does an engineer run them separately?

I just do

go test -v -run Promo ./controllers/leveltriggered/

This did need a tiny bit of preparation: I took the value of KUBEBUILDER_ASSETS from a run of make test and exported it, in .envrc.

@yiannistri
Copy link
Collaborator

Thanks, it was the KUBEBUILDER_ASSETS bit that prompted my question.

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.

2 participants