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

[TestNG] Fix concurrent modification of events #1919

Merged
merged 1 commit into from Mar 12, 2020

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Mar 11, 2020

When a TestNG suite with parallel="methods" is executed TestNG will invoke
all @DataProvider annotated methods. Because these data providers also emit
the TestRunStarted event this event is emitted twice concurrently. These
events collide in the CanonicalOrderEventPublisher resulting in a concurrent
modification that inserts a null element rather then either of the events.

By moving the start of the test execution to the constructor we ensure that
test execution is always started serially. Additionally this ensures that it is
impossible to emit a TestRunFinished event without also emitting a
TestRunStarted event.

This comes at the cost of starting the execution as soon as the @BeforeClass
method is invoked. This will result in some apparent overhead as TestNG is
still preparing for execution.

Fixes: #1917

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • I've added tests for my code.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@coveralls
Copy link

coveralls commented Mar 11, 2020

Coverage Status

Coverage decreased (-0.006%) to 85.942% when pulling 3dc2a45 on concurrent-modification-testng into ca140d4 on master.

When a TestNG suite with `parallel="methods"` is executed TestNG will invoke
all `@DataProvider` annotated methods. Because these data providers also emit
the `TestRunStarted` event this event is emitted twice concurrently. These
events collide in the `CanonicalOrderEventPublisher` resulting in a concurrent
modification that inserts a null element rather then either of the events.

By moving the start of the test execution to the constructor we ensure that
test execution is always started serially. Additionally this ensures that it is
impossible to emit a `TestRunFinished` event without also emitting a
`TestRunStarted` event.

This comes at the cost of starting the execution as soon as the `@BeforeClass`
method is invoked. This will result in some apparent overhead as `TestNG` is
still preparing for execution.

Fixes: #1917
@mpkorstanje mpkorstanje force-pushed the concurrent-modification-testng branch from df883f0 to 3dc2a45 Compare March 11, 2020 23:34
@mpkorstanje mpkorstanje merged commit 7b1e01b into master Mar 12, 2020
@mpkorstanje mpkorstanje deleted the concurrent-modification-testng branch March 12, 2020 10:18
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.

Stream closed exception while trying to finish TestNGCucumberRunner
2 participants