Skip to content

Provide unique IDs for all node info objects#1696

Open
Vampire wants to merge 2 commits into
masterfrom
unique-node-ids
Open

Provide unique IDs for all node info objects#1696
Vampire wants to merge 2 commits into
masterfrom
unique-node-ids

Conversation

@Vampire

@Vampire Vampire commented Jun 10, 2023

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Test specifications, features, and iterations now receive stable, globally unique identifiers for improved tracking and reporting.
    • Feature IDs are derived from their parent spec to preserve traceability between spec and feature.
    • Iterations receive deterministic, index-based identifiers to distinguish parameterized runs.
    • Test nodes expose readable IDs (initially generated) and can be overridden for tooling and reporting.

@Vampire

Vampire commented Jun 10, 2023

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov

codecov Bot commented Jun 10, 2023

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.34%. Comparing base (87e325a) to head (da3f5f4).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1696      +/-   ##
============================================
+ Coverage     82.32%   82.34%   +0.01%     
- Complexity     4877     4879       +2     
============================================
  Files           474      474              
  Lines         15205    15212       +7     
  Branches       1935     1935              
============================================
+ Hits          12518    12526       +8     
  Misses         1993     1993              
+ Partials        694      693       -1     
Files with missing lines Coverage Δ
...va/org/spockframework/runtime/SpecInfoBuilder.java 99.29% <100.00%> (+0.01%) ⬆️
...rg/spockframework/runtime/model/IterationInfo.java 95.45% <100.00%> (+0.21%) ⬆️
...ava/org/spockframework/runtime/model/NodeInfo.java 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 595c6da to 3cacaf6 Compare August 21, 2023 16:15
@leonard84

Copy link
Copy Markdown
Member

What is the use-case? And shouldn't we have something that is stable across invocations, otherwise it's use is severely limited.

@Vampire

Vampire commented Aug 21, 2023

Copy link
Copy Markdown
Member Author

What is the use-case?

Well, everytime you need a unique ID during the test.
One use-case where I needed it is for example to put it as thread context map entry to log messages, so that you can identify log messages belonging to an iteration and test logging behavior in a multi-threaded SUT.

And shouldn't we have something that is stable across invocations, otherwise it's use is severely limited.

Well, the intended use by me was during one test run to relate things, without needing to build a unique ID yourself.
And for spec info, feature info and iteration info, it actually is stable across invocations, just not for "other" nodes.
Others being data provider info, field info, method info and parameter info.

Not sure whether we need stable unique ids for those. :-/

@Vampire

Vampire commented Aug 22, 2023

Copy link
Copy Markdown
Member Author

Also, that they are stable across invocations for spec, feature, and iteration info is mainly a side-effect. The goal was to have something descriptive that can the also easily be readable for example in the log output where I intend to use it. :-D

@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 82329d4 to 9e20670 Compare September 16, 2023 10:37
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 0a54c3f to 53f0557 Compare September 18, 2023 23:41
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 5c9ac8c to 02aff00 Compare October 14, 2023 11:36
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 6e21a45 to b3d7dbb Compare November 7, 2023 00:29
@Vampire Vampire force-pushed the unique-node-ids branch 4 times, most recently from 2caee62 to 6c400f0 Compare November 13, 2023 00:50
@Vampire Vampire force-pushed the unique-node-ids branch 4 times, most recently from 0422e2b to d6e3be7 Compare November 30, 2023 13:08
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 937bf52 to 60bf169 Compare May 16, 2024 10:24
@Vampire Vampire force-pushed the unique-node-ids branch from 60bf169 to 9bffe3b Compare May 22, 2024 14:43
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 3b8d246 to b322fb9 Compare August 8, 2024 09:17
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from ad0c185 to 92d0a32 Compare January 22, 2025 19:01
@Vampire Vampire force-pushed the unique-node-ids branch 4 times, most recently from 3080aad to 06b7338 Compare February 28, 2025 14:36
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 00a4141 to 307e4dc Compare April 27, 2025 23:22
@Vampire Vampire force-pushed the unique-node-ids branch from 307e4dc to 888f6ee Compare May 19, 2025 14:03
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from a01553f to f410524 Compare June 5, 2025 14:46
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 968bbe9 to c434efe Compare October 20, 2025 17:03
@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java`:
- Around line 33-35: The iteration ID is being built with locale-sensitive
String.format in the IterationInfo constructor
(setUniqueId(String.format("%s[%d]", ...))), which can produce locale-specific
digits; change this to a locale-independent construction—either use simple
String concatenation (feature.getUniqueId() + "[" + iterationIndex + "]") or
call String.format(Locale.ROOT, "%s[%d]", feature.getUniqueId(),
iterationIndex)—so setUniqueId always receives a stable, locale-neutral
identifier.

In `@spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java`:
- Around line 38-52: The public mutator setUniqueId on NodeInfo exposes and
allows replacing the node's uniqueId (and setting null/duplicates); remove or
restrict that mutator and enforce one-time, non-null assignment instead: either
make setUniqueId non-public (protected or package-private) or eliminate it and
assign uniqueId during construction, and if you keep an assignment method ensure
it throws on null or if uniqueId is already set (idempotent write-protection).
Update references to getUniqueId, setUniqueId and the uniqueId field accordingly
so only internal/runtime code can set the ID and callers cannot overwrite it.
- Around line 23-31: NodeInfo currently eagerly allocates a UUID in the field
declaration and exposes a public setUniqueId, causing wasted allocations
(IterationInfo immediately replaces it) and allowing external mutation; change
uniqueId to not be eagerly generated (e.g. initialize to null and lazily create
on first getUniqueId OR require subclasses to supply a semantic id via
constructor), replace the public setUniqueId with a non-public API (make it
private/protected or remove it) and, if desired, implement a cheap per-execution
id generator (static AtomicLong counter) that subclasses or getUniqueId can use
to produce lightweight unique values; update NodeInfo.getUniqueId/setters and
constructors of SpecInfo, FeatureInfo, IterationInfo accordingly to ensure
immutability of the identifier.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d290a688-11d0-4184-abc2-413afcc836e3

📥 Commits

Reviewing files that changed from the base of the PR and between 9c6342c and 612a600.

📒 Files selected for processing (3)
  • spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java
  • spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java
  • spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java

Comment on lines +23 to +31
import java.util.UUID;

/**
* Base class for runtime information about an element in a Spock specification.
*
* @author Peter Niederwieser
*/
public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> {
private String uniqueId = UUID.randomUUID().toString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine NodeInfo.java
find . -type f -name "NodeInfo.java" | head -20

Repository: spockframework/spock

Length of output: 137


🏁 Script executed:

# Check the full content of NodeInfo.java
if [ -f "spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java" ]; then
  cat -n "spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java"
else
  # Search for the file
  find . -name "NodeInfo.java" -type f
fi

Repository: spockframework/spock

Length of output: 3665


🏁 Script executed:

# Also check SpecInfoBuilder.java to see if it assigns semantic IDs
find . -type f -name "SpecInfoBuilder.java" | head -5

Repository: spockframework/spock

Length of output: 138


🏁 Script executed:

# Check IterationInfo.java
find . -type f -name "IterationInfo.java" | head -5

Repository: spockframework/spock

Length of output: 142


🏁 Script executed:

# Examine SpecInfoBuilder.java to find semantic ID assignments
cat -n "spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java"

Repository: spockframework/spock

Length of output: 10958


🏁 Script executed:

# Examine IterationInfo.java 
cat -n "spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java"

Repository: spockframework/spock

Length of output: 5336


🏁 Script executed:

# Search for setUniqueId calls to verify overwriting of uniqueId
rg "setUniqueId" -n --context 3

Repository: spockframework/spock

Length of output: 3267


Avoid eagerly generating a UUID in the base type.

SpecInfo, FeatureInfo, and IterationInfo each overwrite the default UUID with semantic IDs. On the per-iteration path, this causes unnecessary UUID allocation overhead—each IterationInfo constructor immediately discards the generated UUID. A per-execution counter would satisfy the documented uniqueness requirement without the allocation cost.

Additionally, the public setUniqueId() setter (lines 50–52) weakens the API contract by allowing arbitrary mutation of what should be an immutable identifier.

💡 One possible simplification
-import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLong;
 
 public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> {
-  private String uniqueId = UUID.randomUUID().toString();
+  private static final AtomicLong NEXT_ID = new AtomicLong();
+  private String uniqueId = "node-" + NEXT_ID.incrementAndGet();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java`
around lines 23 - 31, NodeInfo currently eagerly allocates a UUID in the field
declaration and exposes a public setUniqueId, causing wasted allocations
(IterationInfo immediately replaces it) and allowing external mutation; change
uniqueId to not be eagerly generated (e.g. initialize to null and lazily create
on first getUniqueId OR require subclasses to supply a semantic id via
constructor), replace the public setUniqueId with a non-public API (make it
private/protected or remove it) and, if desired, implement a cheap per-execution
id generator (static AtomicLong counter) that subclasses or getUniqueId can use
to produce lightweight unique values; update NodeInfo.getUniqueId/setters and
constructors of SpecInfo, FeatureInfo, IterationInfo accordingly to ensure
immutability of the identifier.

@testlens-app

This comment has been minimized.

@testlens-app

testlens-app Bot commented Jul 8, 2026

Copy link
Copy Markdown

🚨 TestLens detected 4 failed tests 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Verify Branches and PRs / Build and Verify (2.5, 8, windows-latest) > :spock-specs:test

Test Runs
AsyncConditionsSpec > passing example - check passes ❌ ❌

Verify Branches and PRs / Build and Verify (3.0, 8, windows-latest) > :spock-specs:test

Test Runs
AsyncConditionsSpec > multiple passing evals 🚫 ❌
BlockingVariablesSpec > failing example 1 - variable has wrong value 🚫 ❌

Verify Branches and PRs / Build and Verify (4.0, 8, windows-latest) > :spock-specs:test

Test Runs
BlockingVariablesSpec > failing example 1 - variable has wrong value ❌ ✅
BlockingVariablesSpec > multiple variables ❌ ✅
BlockingVariablesSpec > passing example 2 - variable is read before it is written ✅ ❌

🏷️ Commit: da3f5f4
▶️ Tests: 12561 executed
⚪️ Checks: 61/61 completed

Test Failures

AsyncConditionsSpec > passing example - check passes (:spock-specs:test in Verify Branches and PRs / Build and Verify (2.5, 8, windows-latest))
Async conditions timed out after 1.00 seconds; 1 out of 1 evaluate blocks did not complete in time
	at spock.util.concurrent.AsyncConditions.await(AsyncConditions.java:144)
	at spock.util.concurrent.AsyncConditions.await(AsyncConditions.java:122)
	at spock.util.concurrent.AsyncConditionsSpec.passing example - check passes(AsyncConditionsSpec.groovy:34)
AsyncConditionsSpec > multiple passing evals (:spock-specs:test in Verify Branches and PRs / Build and Verify (3.0, 8, windows-latest))
Async conditions timed out after 1.00 seconds; 2 out of 3 evaluate blocks did not complete in time
	at spock.util.concurrent.AsyncConditions.await(AsyncConditions.java:144)
	at spock.util.concurrent.AsyncConditions.await(AsyncConditions.java:122)
	at spock.util.concurrent.AsyncConditionsSpec.multiple passing evals(AsyncConditionsSpec.groovy:112)
BlockingVariablesSpec > failing example 1 - variable has wrong value (:spock-specs:test in Verify Branches and PRs / Build and Verify (3.0, 8, windows-latest))
Expected exception of type 'org.spockframework.runtime.ConditionNotSatisfiedError', but got 'org.spockframework.runtime.SpockTimeoutError'
	at org.spockframework.runtime.extension.builtin.FailsWithInterceptor.intercept(FailsWithInterceptor.java:44)
	at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:139)
	at org.spockframework.runtime.extension.builtin.TimeoutInterceptor.intercept(TimeoutInterceptor.java:99)
	at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:139)
	at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:157)
	at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:157)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:389)
	at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
	at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:157)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:389)
	at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
Caused by: BlockingVariable.get() timed out after 1.00 seconds
	at spock.util.concurrent.BlockingVariable.get(BlockingVariable.java:114)
	at spock.util.concurrent.BlockingVariablesImpl.get(BlockingVariablesImpl.java:35)
	at spock.util.concurrent.BlockingVariables.getProperty(BlockingVariables.groovy:110)
	at spock.util.concurrent.BlockingVariablesSpec.failing example 1 - variable has wrong value(BlockingVariablesSpec.groovy:63)
BlockingVariablesSpec > passing example 2 - variable is read before it is written (:spock-specs:test in Verify Branches and PRs / Build and Verify (4.0, 8, windows-latest))
org.spockframework.runtime.SpockMultipleFailuresError: Multiple Failures (4 failures)
	org.spockframework.runtime.SpockTimeoutError: BlockingVariable.get() timed out after 1.00 seconds
	org.spockframework.runtime.SpockTimeoutError: BlockingVariable.get() timed out after 1.00 seconds
	org.spockframework.runtime.SpockTimeoutError: BlockingVariable.get() timed out after 1.00 seconds
	org.spockframework.runtime.SpockTimeoutError: BlockingVariable.get() timed out after 1.00 seconds
	at org.spockframework.runtime.ErrorInfoCollector.assertEmpty(ErrorInfoCollector.java:32)
	at org.spockframework.runtime.IterationNode.execute(IterationNode.java:52)
	at org.spockframework.runtime.IterationNode.execute(IterationNode.java:13)
	at org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
	at org.spockframework.runtime.IterationNode.lambda$around$0(IterationNode.java:68)
	at org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunIteration$5(PlatformSpecRunner.java:244)
	at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:157)
	at org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:442)
	at org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:425)
	at org.spockframework.runtime.PlatformSpecRunner.runIteration(PlatformSpecRunner.java:226)
	at org.spockframework.runtime.IterationNode.around(IterationNode.java:68)
	at org.spockframework.runtime.IterationNode.around(IterationNode.java:13)
	at org.spockframework.runtime.SimpleFeatureNode.execute(SimpleFeatureNode.java:58)
	at org.spockframework.runtime.SimpleFeatureNode.execute(SimpleFeatureNode.java:19)
	at org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
	at org.spockframework.runtime.FeatureNode.lambda$around$0(FeatureNode.java:73)
	at org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunFeature$4(PlatformSpecRunner.java:208)
	at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:157)
	at org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:442)
	at org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:425)
	at org.spockframework.runtime.PlatformSpecRunner.runFeature(PlatformSpecRunner.java:199)
	at org.spockframework.runtime.FeatureNode.around(FeatureNode.java:73)
	at org.spockframework.runtime.FeatureNode.around(FeatureNode.java:30)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:389)
	at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
	at org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
	at org.spockframework.runtime.SpecNode.lambda$around$0(SpecNode.java:72)
	at org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunSpec$0(PlatformSpecRunner.java:66)
	at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:157)
	at org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:442)
	at org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:425)
	at org.spockframework.runtime.PlatformSpecRunner.runSpec(PlatformSpecRunner.java:59)
	at org.spockframework.runtime.SpecNode.around(SpecNode.java:72)
	at org.spockframework.runtime.SpecNode.around(SpecNode.java:12)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:389)
	at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)

Muted Tests

Select tests to mute in this pull request:

  • AsyncConditionsSpec > multiple passing evals
  • AsyncConditionsSpec > passing example - check passes
  • BlockingVariablesSpec > failing example 1 - variable has wrong value
  • BlockingVariablesSpec > multiple variables
  • BlockingVariablesSpec > passing example 2 - variable is read before it is written

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app.

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