Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix bucket cleanup in S3 test#7172

Merged
bentsherman merged 2 commits into
masterfrom
fix-test-s3-bucket-leak
May 22, 2026
Merged

Fix bucket cleanup in S3 test#7172
bentsherman merged 2 commits into
masterfrom
fix-test-s3-bucket-leak

Conversation

@bentsherman

Copy link
Copy Markdown
Member

Fixes an S3 unit test that creates a bucket without deleting it on cleanup

@netlify

netlify Bot commented May 22, 2026

Copy link
Copy Markdown

Deploy Preview for nextflow-docs-staging canceled.

Name Link
🔨 Latest commit 1a5f18c
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/6a106e08a6cf830008711e69

Signed-off-by: jorgee <[email protected]>
@jorgee

jorgee commented May 22, 2026

Copy link
Copy Markdown
Contributor

I have fixed the test and checked that all buckets have been removed.

@bentsherman

Copy link
Copy Markdown
Member Author

Thanks Jorge

Interesting explanation from claudio about why def vs final matters here:

Yes — it's a consequence of how Spock restructures the method bytecode to support cleanup:.

Spock's AST transformation wraps the test body in a try/finally so that cleanup: always runs, even when the test throws. To make a variable declared in given: reachable inside that finally block, Spock has to hoist the declaration to the top of the method (outside the try), separate from the assignment:

// What Spock generates (roughly)
def bucketName = null          // hoisted declaration
try {
    bucketName = createBucket() // given: assignment
    Files.delete(...)           // when:
    ...                         // then:
} finally {
    deleteBucket(bucketName)    // cleanup:
}

That two-step pattern — declare-then-assign — is illegal for final variables. A final local must be assigned exactly once, at its declaration site. So when Spock tries to emit final bucketName = null at the top of the method and bucketName = createBucket() inside the try, the compiler rejects it with "might not have been initialized" (or a similar definite-assignment error).

With def, the same split is fine because the variable is just a nullable reference with no assignment-once constraint.

The reason this was invisible before your change: the original test had no cleanup: block, so Spock never needed to hoist bucketName outside the try — it stayed a normal local variable in the given: scope and final was harmless there.

@bentsherman bentsherman merged commit 4fcc583 into master May 22, 2026
23 checks passed
@bentsherman bentsherman deleted the fix-test-s3-bucket-leak branch May 22, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants