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

test: enable integration tests against real S3 (fixes #1899) #1951

Merged
merged 6 commits into from
Sep 16, 2022

Conversation

iwasakims
Copy link
Contributor

@iwasakims iwasakims commented Sep 12, 2022

What this PR changes/adds

Make S3 endpoint configurable via system properties.

Why it does that

For running integration tests against real S3 instead of Minio.

Further notes

I ran tests against Tokyo region with the following command lines using my AWS credential.

$ ./gradlew -p extensions/control-plane/provision/s3-provision clean test -DincludeTags="AwsS3IntegrationTest" --tests '*S3StatusCheckerIntegrationTest' -Dit.aws.profile=iwasakims -Dit.aws.endpoint=https://s3.ap-northeast-1.amazonaws.com/ -Dit.aws.region=ap-northeast-1

> Task :extensions:control-plane:provision:s3-provision:test

---------------------------------------------------------------
|  Results: SUCCESS (6 tests, 6 passed, 0 failed, 0 skipped)  |
---------------------------------------------------------------

and.

$ ./gradlew -p extensions/data-plane/data-plane-s3 clean test -DincludeTags="IntegrationTest" --tests '*S3DataPlaneIntegrationTest' -Dit.aws.profile=iwasakims -Dit.aws.endpoint=https://s3.ap-northeast-1.amazonaws.com/ -Dit.aws.region=ap-northeast-1

> Task :extensions:data-plane:data-plane-s3:test

---------------------------------------------------------------
|  Results: SUCCESS (1 tests, 1 passed, 0 failed, 0 skipped)  |
---------------------------------------------------------------

Linked Issue(s)

Closes #1899

Checklist

  • [n/a] added appropriate tests?
  • performed checkstyle check locally?
  • added/updated copyright headers?
  • [n/a] documented public classes/methods?
  • added/updated relevant documentation?
  • assigned appropriate label? (exclude from changelog with label no-changelog)
  • formatted title correctly? (take a look at the CONTRIBUTING and styleguide for details)

@iwasakims iwasakims temporarily deployed to Azure-dev September 12, 2022 16:21 Inactive
@iwasakims iwasakims added the enhancement New feature or request label Sep 12, 2022
@iwasakims iwasakims self-assigned this Sep 12, 2022
@ndr-brt ndr-brt self-requested a review September 13, 2022 07:35
private static boolean isMinio() {
return MINIO_ENDPOINT.equals(S3_ENDPOINT.toString());
}

/**
* pings <a href="https://docs.min.io/minio/baremetal/monitoring/healthcheck-probe.html">MinIO's health endpoint</a>
*
* @return true if HTTP status [200..300[
*/
private static boolean pingMinio() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

At this point I would rename this method, the name is not consistent and it does not explain the result.
Could be refactored in something like:

    @BeforeAll
    static void prepareAll() {
        await().atLeast(Duration.ofSeconds(2))
                .atMost(Duration.ofSeconds(15))
                .with()
                .pollInterval(Duration.ofSeconds(2))
                .ignoreException(IOException.class) // thrown by minioIsAvailable
                .ignoreException(ConnectException.class)
                .until(() -> {
                    if (isMinio()) {
                        return minioIsAvailable();
                    } else {
                        return true;
                    }
                });
    }

    private static boolean isMinio() {
        return MINIO_ENDPOINT.equals(S3_ENDPOINT.toString());
    }

    /**
     * pings <a href="https://docs.min.io/minio/baremetal/monitoring/healthcheck-probe.html">MinIO's health endpoint</a>
     *
     * @return true if HTTP status [200..300[
     */
    private static boolean minioIsAvailable() throws IOException {
        var httpClient = new OkHttpClient();
        var healthRq = new Request.Builder().url(S3_ENDPOINT + "/minio/health/live").get().build();
        try (var response = httpClient.newCall(healthRq).execute()) {
            return response.isSuccessful();
        }
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code based on your suggestion. I chose isMinioAvailable preferring is* for the name of method returning boolean. @ndr-brt

@@ -158,7 +166,7 @@ protected void putStringOnBucket(String bucketName, String key, String content)
}

protected @NotNull AwsCredentials getCredentials() {
String profile = propOrEnv("AWS_PROFILE", null);
String profile = propOrEnv("it.aws.profile", null);
Copy link
Member

Choose a reason for hiding this comment

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

please use var

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@paullatzelsperger
Copy link
Member

before I review this, please fix the failing tests.

@iwasakims
Copy link
Contributor Author

@paullatzelsperger The cause seems to be running S3DataPlaneIntegrationTest without starting Minio in unexpected jobs like Postgresql-Integration-Tests and Hashicorp-Vault-Integration-Tests. I expect #1897 to address this.

Let me rebase this PR and address review comment of @ndr-brt.

@iwasakims
Copy link
Contributor Author

iwasakims commented Sep 15, 2022

The cause of the test failure is change of build.gradle.kts overwriting test task setting for skipping IntegrationTests. I will revert the change of build.gradle.kts. We can use environment variable instead of system properties without fixing build.gradle.kts.

$ IT_AWS_PROFILE=iwasakims IT_AWS_ENDPOINT=https://s3.ap-northeast-1.amazonaws.com/ IT_AWS_REGION=ap-northeast-1 ./gradlew -p extensions/data-plane/data-plane-s3 clean test -DincludeTags="IntegrationTest" --tests '*S3DataPlaneIntegrationTest' 

@iwasakims iwasakims temporarily deployed to Azure-dev September 15, 2022 10:03 Inactive
@@ -83,15 +85,25 @@ static void prepareAll() {
.pollInterval(Duration.ofSeconds(2))
.ignoreException(IOException.class) // thrown by pingMinio
.ignoreException(ConnectException.class)
.until(AbstractS3Test::pingMinio);
.until(() -> {
Copy link
Member

@paullatzelsperger paullatzelsperger Sep 15, 2022

Choose a reason for hiding this comment

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

minor nit: introducing a method, something like isBackendAvailable or similar naming would make this piece of code more readable:

    .ignoreException(ConnectException.class)
    .until(this::isBackendAvailable);
}

// and then:
private boolean isBackendAvailable(){
   if(isMinio()){
      return isMinioAvailable();
   } else {
      return true;
   }
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I updated the code.

@iwasakims iwasakims temporarily deployed to Azure-dev September 15, 2022 19:17 Inactive
@iwasakims iwasakims temporarily deployed to Azure-dev September 16, 2022 02:41 Inactive
@codecov-commenter
Copy link

Codecov Report

Merging #1951 (14e2432) into main (9d3e17d) will increase coverage by 0.10%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #1951      +/-   ##
==========================================
+ Coverage   62.78%   62.88%   +0.10%     
==========================================
  Files         781      782       +1     
  Lines       16608    16640      +32     
  Branches     1080     1081       +1     
==========================================
+ Hits        10427    10464      +37     
+ Misses       5730     5726       -4     
+ Partials      451      450       -1     
Impacted Files Coverage Δ
...smos/policy/store/CosmosPolicyDefinitionStore.java 91.30% <0.00%> (-6.32%) ⬇️
...efinition/store/CosmosContractDefinitionStore.java 84.90% <0.00%> (-4.90%) ⬇️
...taspaceconnector/spi/types/domain/asset/Asset.java 91.89% <0.00%> (ø)
...vent/policydefinition/PolicyDefinitionCreated.java 100.00% <0.00%> (ø)
...vent/policydefinition/PolicyDefinitionDeleted.java 100.00% <0.00%> (ø)
...taspaceconnector/sql/assetindex/SqlAssetIndex.java 0.00% <0.00%> (ø)
.../contract/offer/store/ContractDefinitionStore.java 0.00% <0.00%> (ø)
...zure/cosmos/dialect/CosmosConditionExpression.java 91.83% <0.00%> (ø)
...onnector/assetindex/azure/model/AssetDocument.java 100.00% <0.00%> (ø)
...osmos/policy/store/CosmosPolicyStoreExtension.java 0.00% <0.00%> (ø)
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@paullatzelsperger paullatzelsperger merged commit ad4a338 into eclipse-edc:main Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: enable integration tests against real S3
4 participants