google / google/googletest

gmock-actions_test depends on order of test execution

Open
#2,900 0 comments 0 reactions 1 assignee View on GitHub

@derekmauro is already working on this.

Since Jun 23, 2020.

Dominant language
C++
Stars
39.6k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

In gmock-actions_test, tests

  • MockMethodTest.CanReturnMoveOnlyValue_Invoke and
  • DefaultValueTest.GetWorksForMoveOnlyIfSet

both change DefaultValue<std::unique_ptr<int>>::producer_ without restoring the state after the test.

This causes the following failures:

  1. DefaultValueTest.GetWorksForMoveOnlyIfSet fails when it is executed after MockMethodTest.CanReturnMoveOnlyValue_Invoke.
    With 50% chance, the following call fails:
    gmock-actions_test --gtest_filter="MockMethodTest.CanReturnMoveOnlyValue_Invoke:DefaultValueTest.GetWorksForMoveOnlyIfSet" --gtest_shuffle

  2. DefaultValueTest.GetWorksForMoveOnlyIfSet fails when it is executed repeatedly:
    gmock-actions_test --gtest_filter="DefaultValueTest.GetWorksForMoveOnlyIfSet" --gtest_repeat=2

In practice, we observed the problem when executing googletest’s own unit tests on AIX (without shuffle, without repeat), because the test execution order was different than on other platforms.

Since the order of test execution is undefined, the tests should work in any order.

Locally, we fixed the problem by adding the line
DefaultValue<std::unique_ptr<int>>::Clear();
at the end of both tests.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.