{{ message }}
Repository navigation
Reset the port of specs2 WithServer and WithBrowser also when an example fails - #14338
Merged
Merged
Conversation
…ple fails WithServer and WithBrowser set `port` to the port the test server actually uses while an example runs (a random one for port 0), and reset it to the given port afterwards. The reset ran after the server block, but AsResult.effectively throws for every result that isn't a success. So after a failing, erroring, skipped or pending example, `port` kept the server's port. Reset it in a finally block instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
The specs2 scopes
WithServerandWithBrowsersetportto the port the test server actually uses while an example runs. With the default port0, that's a random port. Afterwards they resetportto the port they were given.That reset ran after the server block. However,
AsResult.effectivelythrows for every result that isn't a success: a failure, an error, or a skipped or pending example. So after such an example,portstill contained the server's port.This PR resets
portin afinallyblock in both scopes. InWithBrowser, the existingfinallyblock that quits the browser now resets the port first.The impact is small.
wrapruns only once per scope instance, so the stale port was only visible to code that readsportafter the example, for example through a reference to the scope. Java'sWithServerandWithBrowseraren't affected: they reset the port in a JUnit@Aftermethod, which also runs when a test fails.Docs: the Scaladoc of the
portparameter of both scopes and the specs2 functional testing guide now describe whatportcontains during and after an example.Tests
The new
WithServerPortSpecruns a successful and a failing example in each scope, with port0. It checks thatportis the server's port during the example, and0again afterwards. Without the fix, the two failing-example tests fail, for example with33997 != 0.The spec is in
play-integration-test, because the scopes need a server backend, andplay-specs2's own tests don't have one on their classpath.Locally:
WithServerPortSpecpasses on Scala 2.13.18 and 3.3.8.Play-Specs2tests and MiMa pass on Scala 2.13.18 and 3.3.8.ScalaFunctionalTestSpec, which uses both scopes, passes, and so does the documentation validation.validateCodepasses in the root and indocumentation/.AI assistance
OpenAI Codex noticed this problem while reviewing #14337. Claude (Anthropic) was used to implement the fix, write the tests and draft this pull request. I reviewed the result before submitting.
🤖 Generated with Claude Code