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

Refactor test helpers and clean up random failures #39228

Merged
merged 12 commits into from
Apr 3, 2020

Conversation

wapcaplet
Copy link
Contributor

@wapcaplet wapcaplet commented Apr 3, 2020

Summary

SUMMARY: none

Purpose of change

Several tests were failing when executed with tests/cata_test --order rand with various seeds, due to stale effects or insufficient cleanup/reset between test cases. This fixes several of them.

Describe the solution

  • Prevent gun from being "too big" or "too small" in weapon fouling test (item_tname_test.cpp)
  • Prevent "not in vehicle" requirements from failing in several tests by removing vehicles first
  • Clear all traits and set pain to 0 in clear_character
  • Move helpers into map_helpers.cpp from vehicle_power_test.cpp:
    • Move remove_all_vehicles to clear_vehicles
    • Move build_test_map, and use the shared build_test_map from vehicle_efficiency_test.cpp and vehicle_drag_test.cpp
  • Add [slow] tag to all test cases that took more than 1 second to execute
    • Facilitates running all the "fast" tests with e.g. tests/cata_test ~[slow]~[.]
  • Use REQUIRE_FALSE and CHECK_FALSE where appropriate (instead of !)

Describe alternatives you've considered

Inevitable entropy

Testing

Iterative tests/cata_test --order rand --rng-seed X, sometimes with ~[slow]~[.] to run only the "fast" tests.

Additional context

There are bound to be more that still fail with random seeds, but this knocks out 80% of the ones I could find.

wapcaplet added 12 commits April 1, 2020 19:31
Two test cases were failing when run with `--order rand`,
because of a failed assumption that the player would not be `in_vehicle`
(when in fact other tests spawn vehicles at the same location as
`clear_player`, at 60,60,0).

This commit adds a `clear_vehicles` test helper that removes all
vehicles from the map. The two previously failing test cases now call
`clear_vehicles` before making any assumptions about whether the player
is in the vehicle.

It also changes said assumption to a `REQUIRE_FALSE()` rather than a
`CHECK(!)`.
This test was failing on this bit:

    npc_test.cpp:440: FAILED:
      REQUIRE( rl_dist( g->u.pos(), hostile.pos() ) <= 1 )
    with expansion:
      14 <= 1

It turns out `place_player` with `tripoint( 10, 10, 0 )` in this test
was locating the player at ( 70, 70, 0 ), and the `spawn_npc` function
(by calling `load_npcs`) was positioning the NPC at ( 80, 80, 0 ). I
have no idea why it is doing this.

But using `place_player` with `tripoint( 0, 0, 0 )` for this test case
allows the player to be positioned at ( 60, 60, 0 ) - again, no idea why
- maybe because that position is used by an earlier test? - anyway, this
lets the NPC be placed at ( 60, 61, 0 ) and thus the test can pass.
Based on running `tests/cata_test -d yes` to see durations:

22.254 s: grenade_lethality
9.236 s: starting_items
7.887 s: starve_test
5.416 s: all_nutrition_starve_test
2.904 s: starve_test_hunger3
1.496 s: unskilled_shooter_accuracy
1.490 s: an unskilled shooter with an inaccurate shotgun
1.167 s: default_overmap_generation_always_succeeds
0.953 s: default_overmap_generation_has_non_mandatory_specials_at_origin
The clear_vehicles() helper function is now defined in
player_helpers.(h|cpp)
@kevingranade kevingranade merged commit c35e936 into CleverRaven:master Apr 3, 2020
@wapcaplet wapcaplet deleted the test-helpers branch April 12, 2020 14:46
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