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

Refactored test header logic into a global spock extension #22573

Merged

Conversation

rnpmsft
Copy link
Contributor

@rnpmsft rnpmsft commented Jun 25, 2021

Sooo this is one possible solution for centralizing the header logic, I've gone ahead and removed all header prints throughout the storage SDK in this branch as well. To deal with the classpath issue, I've changed the bundling for shared resources to use maven-assembly-plugin rather than the jar plugin; this way, we can have the META-INF folder somewhere that won't conflict, and redirect it within the jar.

The other solution was using maven-resources-plugin and maven-clean-plugin to move the extension manifest from some location into target/test-classes/META-INF/services right before the test-compile phase, then clean the file out right after (with process-test-classes), but the assembly sol seemed a bit tidier.

File locations and stuff could use some change, I just put everything somewhere it would work. assembly.xml/the manifests folder might do better in a centralized location, since they're only used by the shared build; maybe test-shared/resources (if that doesn't automatically get sent by maven to target/test-classes). We could also put the SpockConfig.groovy into there to separate shared tests resources fully from just common test resources.

One iffy thing in here; I nabbed the getTestName logic from StorageSpec and put it into the extensions for use with printing headers, and this caused code duplication; for now, there's a static reference from StorageSpec into the extension to call the method, which probably should be changed. Any thoughts on fixing that? Maybe just a TestNamer or something that both the spec and extension can use?

@rnpmsft
Copy link
Contributor Author

rnpmsft commented Jun 25, 2021

I should've marked this as a draft; this likely isn't ready for merge before decoupling the extension and spec.

@kasobol-msft
Copy link
Contributor

Did you just solve the META-INF conflict problem ?

@@ -19,10 +20,9 @@ class StorageSpec extends Specification {
private StorageResourceNamer namer

def setup() {
def testName = getTestName()
def testName = TestHeaderExtension.FeatureInterceptor.getTestName(specificationContext.getCurrentIteration())
Copy link
Contributor

Choose a reason for hiding this comment

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

we should create TestNameProvider or something like this and extract getTestName there and use it in both places.
Can be static code.

Comment on lines +142 to +144
<descriptors>
<descriptor>src/test-shared/assembly/assembly.xml</descriptor>
</descriptors>
Copy link
Contributor

Choose a reason for hiding this comment

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

how does the output of this look like in target folder when you run mvn install?

@alzimmermsft does this affect how commons is released to mvncentral anyhow that we should be worried about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maven doesnt copy over the assembly folder/file into target since it's not specified as a resource. the manifests get transferred as a manifests folder into the target/test-classes folder, preventing it from getting caught with common tests, and the assembly plugin maps it where it needs to go in the artifact

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, but does test jar look the same ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I ran jar xf on it and the contents are the same.

Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't affect releasing to Maven central as this only affect building the library from source

@alzimmermsft
Copy link
Member

Appears you've found a bug in the generate_from_source_pom.py script with the azure-storage-common self-reference, I'll submit a PR to fix this that'll need to be pulled into this branch.

@kasobol-msft
Copy link
Contributor

Appears you've found a bug in the generate_from_source_pom.py script with the azure-storage-common self-reference, I'll submit a PR to fix this that'll need to be pulled into this branch.

@alzimmermsft Does that mean this solution will stop working and we should fall back to option 2 mentioned in PR description?

@alzimmermsft
Copy link
Member

This PR should resolve the infinite recursion in the Python script: #22583

@alzimmermsft
Copy link
Member

Appears you've found a bug in the generate_from_source_pom.py script with the azure-storage-common self-reference, I'll submit a PR to fix this that'll need to be pulled into this branch.

@alzimmermsft Does that mean this solution will stop working and we should fall back to option 2 mentioned in PR description?

The current approach is good, I'd rather wrangle a bit more infrastructure that only affects testing rather than move classes around before compilation and clean the up after it.

@rnpmsft
Copy link
Contributor Author

rnpmsft commented Jun 25, 2021

Appears you've found a bug in the generate_from_source_pom.py script with the azure-storage-common self-reference, I'll submit a PR to fix this that'll need to be pulled into this branch.

@alzimmermsft Does that mean this solution will stop working and we should fall back to option 2 mentioned in PR description?

The current approach is good, I'd rather wrangle a bit more infrastructure that only affects testing rather than move classes around before compilation and clean the up after it.

I think either way, the bug fix was necessary; both solutions rely on the META-INF being found in the test jar instead of living in the target folder for common, meaning the self-dependency would have to be there for both options.

I've mirrored your changes, let's see if CI is happy. I've pointed this PR to the feature/storage/DataMovement branch, but this PR addressed a more general issue; should I redirect it to the main branch to merge there when complete?

@gapra-msft
Copy link
Member

Appears you've found a bug in the generate_from_source_pom.py script with the azure-storage-common self-reference, I'll submit a PR to fix this that'll need to be pulled into this branch.

@alzimmermsft Does that mean this solution will stop working and we should fall back to option 2 mentioned in PR description?

The current approach is good, I'd rather wrangle a bit more infrastructure that only affects testing rather than move classes around before compilation and clean the up after it.

I think either way, the bug fix was necessary; both solutions rely on the META-INF being found in the test jar instead of living in the target folder for common, meaning the self-dependency would have to be there for both options.

I've mirrored your changes, let's see if CI is happy. I've pointed this PR to the feature/storage/DataMovement branch, but this PR addressed a more general issue; should I redirect it to the main branch to merge there when complete?

Yes, I think that would be fine if you point this PR to main and then once this PR is merged, merge main into the DataMovement branch

Rushi Patel added 3 commits June 25, 2021 17:18
…nt overriding parent POM + better relay execution goals, removed maven self-dependency (now using surefire classpath dependency)
…er changes to target path), fixed assembly paths for *nix-compatibility
…med variables/class names for clarity, final on new classes
@rnpmsft
Copy link
Contributor Author

rnpmsft commented Jun 28, 2021

Changes until this point:

  • Moved getName() logic to TestNameProider used for the shared spec and extension
  • Removed accidental duplicate print code from testing
  • Changed the maven execution id's for better clarity, and to prevent overwriting parent POM's (current test shared source compile task was overwriting and causing common samples to not get compiled)
  • Removed maven <dependency> on self. This was causing a chicken and egg problem where from a clean build environment, the common package couldn't build as it couldn't find its tests jar... which doesn't build until it's test-compile phase. Instead, there's now an added classpath specified in surefire config, so build doesn't get blocked, but the dependency gets loaded at test time from local repository.
  • Tagged the Extension and NameProvider as final, is that correct?
  • Refactored TestHeaderExtension from Groovy to Java as the rest were already Java; do we want to keep extensions in Java?

@rnpmsft
Copy link
Contributor Author

rnpmsft commented Jun 28, 2021

Changes until this point:

  • Moved getName() logic to TestNameProider used for the shared spec and extension
  • Removed accidental duplicate print code from testing
  • Changed the maven execution id's for better clarity, and to prevent overwriting parent POM's (current test shared source compile task was overwriting and causing common samples to not get compiled)
  • Removed maven <dependency> on self. This was causing a chicken and egg problem where from a clean build environment, the common package couldn't build as it couldn't find its tests jar... which doesn't build until it's test-compile phase. Instead, there's now an added classpath specified in surefire config, so build doesn't get blocked, but the dependency gets loaded at test time from local repository.
  • Tagged the Extension and NameProvider as final, is that correct?
  • Refactored TestHeaderExtension from Groovy to Java as the rest were already Java; do we want to keep extensions in Java?

@alzimmermsft Any issues here?

@gapra-msft
Copy link
Member

Resolves #22458

Copy link
Member

@alzimmermsft alzimmermsft left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@kasobol-msft kasobol-msft merged commit 7119e23 into Azure:main Jun 28, 2021
@rnpmsft rnpmsft deleted the feature/storage/shared-test-header-logic branch June 28, 2021 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test improvement: Get rid of duplicate setup code that prints test name, centralize that logic
4 participants