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

tests(busted): make all setup() and teardown() calls lazy #13984

Merged
merged 1 commit into from
Dec 9, 2024
Merged

Conversation

flrgh
Copy link
Contributor

@flrgh flrgh commented Dec 6, 2024

This adds the lazy setting to our .busted file. This is the equivalent of adding the --lazy flag when running the busted CLI, which essentially causes every setup() and teardown() invocation to behave like lazy_setup() and lazy_teardown().

We have a bunch of test files that are using setup()/teardown() instead of the lazy_ variants, and making one small change to the .busted file saves us the trouble of updating all of them (including EE).

what's the difference between setup() and lazy_setup()?

setup() always runs, whereas lazy_setup() only runs if at least one test case (it(...)) is scheduled to run:

describe("strict", function()
  setup(function()
    -- I always run, even if the following test is skipped
    print("[strict] doing setup things")
  end)

  it("my test #skipme", function() end)
end)

describe("lazy", function()
  lazy_setup(function()
    -- I only run when the following test is not skipped
    print("[lazy] doing setup things")
  end)

  it("my test #skipme", function() end)
end)

We commonly filter out tests with the --exclude-tags CLI option in CI. The strict behavior is not ideal in this case, because it means that expensive setup/teardown tasks run even if we've completely filtered out all accompanied tests:

$ busted -o htest test_spec.lua  --exclude-tags skipme
======= Running tests from scanned files.
------- Global test environment setup.
------- Running tests from test_spec.lua :
[strict] doing setup things
------- 0 tests from test_spec.lua (0.24 ms total)

------- Global test environment teardown.
======= 0 tests from 1 test file ran. (0.41 ms total)
PASSED  0 tests.

If any test authors specifically need the strictness of setup()/teardown(), they can use strict_setup()/strict_teardown():

https://lunarmodules.github.io/busted/#defining-tests


KAG-5962

@github-actions github-actions bot added the cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee label Dec 6, 2024
@flrgh flrgh marked this pull request as draft December 6, 2024 02:12
@pull-request-size pull-request-size bot added size/XS and removed size/L labels Dec 6, 2024
@flrgh flrgh changed the title tests(busted): use lazy_ variants of setup/teardown helpers tests(busted): make all setup() and teardown() calls lazy Dec 6, 2024
@flrgh flrgh marked this pull request as ready for review December 6, 2024 05:36
This turns on the `--lazy` flag for busted, which has the effect of
making all `setup()` and `teardown()` invocations behave as
`lazy_setup()` and `lazy_teardown()`.
@flrgh flrgh merged commit 7eecd96 into master Dec 9, 2024
31 checks passed
@flrgh flrgh deleted the tests/lazy branch December 9, 2024 22:14
@team-gateway-bot
Copy link
Collaborator

Successfully created cherry-pick PR for master:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee size/XS skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants