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 tests for create source git #1696

Merged
merged 1 commit into from
Aug 30, 2021
Merged

Conversation

allenporter
Copy link
Contributor

@allenporter allenporter commented Aug 7, 2021

Add unit tests for create source git.

The create source tests are more interesting than the existing unit tests as they
create objects then wait for the flux source reconciler to complete. The tests
simulate this with a background goroutine that waits for an object to be
created then uses a test specific function to update it. The reconciler was
implemented assuming that it might be possible to make it more generic
in the future if needed by additional tests.

The tests set a timeout so that if there is a failure they timeout somewhat
quickly rather than hanging for a longer period of time.

Issue #1603

@allenporter allenporter changed the title Add tests for create source git Add tests for create source git Aug 7, 2021
@allenporter
Copy link
Contributor Author

@chanwit as an FYI

@chanwit
Copy link
Contributor

chanwit commented Aug 8, 2021 via email

@allenporter allenporter changed the title Add tests for create source git Add tests for create source git and make test harness more flexible Aug 12, 2021
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

LGTM, and seems to be indeed the fix for the other test-related PR :-)

@allenporter
Copy link
Contributor Author

@hiddeco i'm having trouble merging this with the e2e tests that were just added. Do you have a workflow for running the e2e tests with extra logging enabled? My iteration cycle is pretty high having to wait for github actions to run -- or perhaps you can lend a pair of eyes and spot if i added a bug.

@hiddeco
Copy link
Member

hiddeco commented Aug 17, 2021

@chanwit @stefanprodan anything standing out from the PR that got merged into main that could cause conflicts with this one? I can't find an obvious reason on a first scan.

@stefanprodan
Copy link
Member

We can’t use the install test, I’m dropping it, PR will follow.

@stefanprodan
Copy link
Member

Please see #1721

@stefanprodan
Copy link
Member

@allenporter @hiddeco @chanwit I'm for dropping the mock API and use envtest.

@chanwit
Copy link
Contributor

chanwit commented Aug 17, 2021

No objection @stefanprodan

@stefanprodan
Copy link
Member

In the latest controller-runtime release, the testenv startup time has improve a lot, I think we need to port the flux trace from mock the API to testenv (without kind) and compare the timing.

@allenporter
Copy link
Contributor Author

allenporter commented Aug 17, 2021

In the latest controller-runtime release, the testenv startup time has improve a lot, I think we need to port the flux trace from mock the API to testenv (without kind) and compare the timing.

1: On Testenv

Great, as I mentioned up on the other PR, having fewer test environments would be ideal if its speedy. Now that the e2e and unit tests share the same harness, but not the same setup, it seems easy to accidentally break the e2e tests while iterating on the unit tests, so removing the differences would be nice.

@chanwit hav you exercised TestEnvClusterMode to run tests locally yet? I could use a few pointers to get started and understanding how the Makefile is supposed to work:

$ make setup-envtest SHELL='sh -x'
+ which setup-envtest
make: Nothing to be done for 'setup-envtest'.

2: On running e2e tests, back to my question above: Do you have a workflow for running the e2e tests locally? I'm having difficulty telling if the e2e tests are still flaky or i'm breaking it. I'm assuming they are still flaky given the error messages are related to deadline exceeded. I don't seem to be able to Retry jobs (maybe a permissions thing).

3: Stepping back: The approach in this PR is to be able to support more complex test types to be able to exercise edge cases such as waiting for the results of a controller to run. I keep seeing more PRs coming in adding tests with the old harness in parallel with this so I'd like to make sure this is useful before doing more catchup. Is this a useful direction or should I abandon this?

@hiddeco
Copy link
Member

hiddeco commented Aug 17, 2021

Is this a useful direction or should I abandon this?

I think the new direction (yours) is more useful and we should probably look into transforming the others.

@allenporter
Copy link
Contributor Author

Is this a useful direction or should I abandon this?

I think the new direction (yours) is more useful and we should probably look into transforming the others.

OK if we get the unit tests using testenv then maybe there will be less of a distinction between the two scenarios and we can leave a few e2e tests.

@stefanprodan
Copy link
Member

Looks like the client is not wired correctly now, no types are registered.

@allenporter allenporter marked this pull request as draft August 17, 2021 20:07
@allenporter
Copy link
Contributor Author

allenporter commented Aug 17, 2021

Looks like the client is not wired correctly now, no types are registered.

Correct -- the changes to the test harness to support the e2e end test have broken the fake harness wiring via rootCtx.kubeManager.

More detail:

  • main_e2e_test invokes the test setup and rootCtx.kubeManager We can call this testEnv #1
  • The tests themselves run again and run cmdTestCase.runTestCmd which also sets up the test environment and overrides rootCtx.kubeManager again. We can call this testEnv #2
  • The PR to update the e2e harness introduced a test that calls create source git which is the same thing that is being tested in this PR coincidentally
  • This PR updates create source git to use the rootCtx.kubeManager to create the client library for the test since its tested with the fake. That has the side effect of making this command use testEnv #2
  • Most of the code has not yet been updated to use rootCtx.kubeManager so it works as is with the e2e test by setting the flags and always using testEnv #1

I'll start unwinding this...

allenporter added a commit to allenporter/flux2 that referenced this pull request Aug 23, 2021
Replace the 4 arguments to cmdTestCase with a function that
can let tests run arbitrary logic if it is more complex than
what is provided by the test harness. Move the existing logic
into functions that the test can use for common checks on
golden files and golden values.

These changes were pulled out of PR fluxcd#1696 to make a smaller review.

Signed-off-by: Allen Porter <allen@thebends.org>
allenporter added a commit to allenporter/flux2 that referenced this pull request Aug 23, 2021
Replace the 4 arguments to cmdTestCase with a function that
can let tests run arbitrary logic if it is more complex than
what is provided by the test harness. Move the existing logic
into functions that the test can use for common assertions on
golden files and golden values.

These changes were pulled out of PR fluxcd#1696 to make a smaller review.

Signed-off-by: Allen Porter <allen@thebends.org>
@allenporter allenporter changed the title Add tests for create source git and make test harness more flexible Add tests for create source git Aug 24, 2021
@allenporter allenporter marked this pull request as ready for review August 24, 2021 19:53
@allenporter allenporter force-pushed the flux-cmd-create branch 2 times, most recently from 8200ac3 to 4d0a1e8 Compare August 25, 2021 20:16
The create source tests are more interesting than the existing tests as they
create objects then wit for the flux source reconciler to complete. The tests
simulate this with a background goroutine that waits for an object to be
created then uses a test specific function to update it.

The tests set a timeout so that if there is a failure they timeout somewhat
quickly rather than hanging for a longer period of time.

Signed-off-by: Allen Porter <allen@thebends.org>
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @allenporter 💯

@hiddeco hiddeco merged commit 06fa8f7 into fluxcd:main Aug 30, 2021
souleb pushed a commit to souleb/flux2 that referenced this pull request Jul 10, 2023
Replace the 4 arguments to cmdTestCase with a function that
can let tests run arbitrary logic if it is more complex than
what is provided by the test harness. Move the existing logic
into functions that the test can use for common assertions on
golden files and golden values.

These changes were pulled out of PR fluxcd#1696 to make a smaller review.

Signed-off-by: Allen Porter <allen@thebends.org>
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.

None yet

4 participants