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

S3 settings functional tests #2837

Merged

Conversation

osulzhenko
Copy link
Collaborator

No description provided.

@osulzhenko osulzhenko force-pushed the s3-settings-functional-tests branch from 8abb1a6 to 371673a Compare December 14, 2023 08:16
@SerhiiNahornyi
Copy link
Collaborator

@muuki88 We added a few tests for your PR
#2837

Could you pls review them with us?

@muuki88
Copy link
Contributor

muuki88 commented Dec 14, 2023

Sure thing 😃 I'll try to review ASAP

@osulzhenko osulzhenko added the tests Functional or other tests label Dec 15, 2023
Copy link
Contributor

@muuki88 muuki88 left a comment

Choose a reason for hiding this comment

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

First of all: kudos to the structure of your functional tests. Super comfortable to read and understand. Even though most of them look like they could be unit tests 😄

3 of the 4 failing tests make totally sense. The one with .secure property I don't get, because I'm not familiar with this feature and what the intention is.

My question is: Do you have the capacity to add the missing checks to make the tests green?

assert exception.responseBody == "Account $accountId is inactive"
}

def "PBS should throw exception when account have different id inside json in S3 storage"() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test makes sense and the implementation is missing this check

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

assert bidderRequest.regs?.gdpr == ampStoredRequest.regs.ext.gdpr
}

def "PBS should throw exception when trying to take parameters from the stored request on S3 service with invalid id in file"() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test makes sense and currently fails in the pipeline.

assert bidderRequest.imp[0].secure == secureStoredRequest
}

def "PBS should throw exception when trying populate imp[0].secure from imp stored request on S3 service with invalid impId in file"() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def "PBS should throw exception when trying populate imp[0].secure from imp stored request on S3 service with invalid impId in file"() {
def "PBS should throw exception when trying to populate imp[0].secure from imp stored request on S3 service with invalid impId in file"() {

This test I don't understand. What is in imp[0].secure that this fails the test? Is this another layer of checksum/validation to ensure the integrity of the configuration?

Copy link
Contributor

Choose a reason for hiding this comment

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

assert !bidder.getRequestCount(bidRequest.id)
}

def "PBS should throw request format exception when stored auction response have different id inside S3 file"() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably sane to do that filename and ID match.

Comment on lines 31 to 34
this.localStackContainer = new LocalStackContainer(DockerImageName.parse("localstack/localstack:s3-latest"))
.withNetwork(Dependencies.network)
.withServices(LocalStackContainer.Service.S3)
localStackContainer.start()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Creation of LSContainet should be in Dependencies.groovy

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

localStackContainer.getAccessKey(), localStackContainer.getSecretKey())))
.region(Region.of(localStackContainer.getRegion()))
.build()
createBucket(bucketName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be great to remove call of createBucket(...) from constuructor

Comment on lines 30 to 41
S3Service(String bucketName) {
this.localStackContainer = new LocalStackContainer(DockerImageName.parse("localstack/localstack:s3-latest"))
.withNetwork(Dependencies.network)
.withServices(LocalStackContainer.Service.S3)
localStackContainer.start()
s3PbsService = S3Client.builder()
.endpointOverride(localStackContainer.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localStackContainer.getAccessKey(), localStackContainer.getSecretKey())))
.region(Region.of(localStackContainer.getRegion()))
.build()
createBucket(bucketName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better formating

Suggested change
S3Service(String bucketName) {
this.localStackContainer = new LocalStackContainer(DockerImageName.parse("localstack/localstack:s3-latest"))
.withNetwork(Dependencies.network)
.withServices(LocalStackContainer.Service.S3)
localStackContainer.start()
s3PbsService = S3Client.builder()
.endpointOverride(localStackContainer.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localStackContainer.getAccessKey(), localStackContainer.getSecretKey())))
.region(Region.of(localStackContainer.getRegion()))
.build()
createBucket(bucketName)
s3PbsService = S3Client.builder()
.endpointOverride(localStackContainer.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
localStackContainer.getAccessKey(),
localStackContainer.getSecretKey())))
.region(Region.of(localStackContainer.getRegion()))
.build()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

protected static final String INVALID_FILE_BODY = 'INVALID'
protected static final def DEFAULT_BUCKET = PBSUtils.randomString.toLowerCase()

protected static final S3Service S3_SERVICE = new S3Service(DEFAULT_BUCKET)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks weard when on constant we call method like here S3_SERVICE.uploadStoredResponse(...)
As for me would be great move to lower case s3Service

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

class StorageBaseSpec extends BaseSpec {

protected static final String INVALID_FILE_BODY = 'INVALID'
protected static final def DEFAULT_BUCKET = PBSUtils.randomString.toLowerCase()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pretty minor, for consistency move def to String

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 16 to 25
protected static Map<String, String> s3StorageConfig = [
'settings.s3.accessKeyId' : "${S3_SERVICE.accessKeyId}".toString(),
'settings.s3.secretAccessKey' : "${S3_SERVICE.secretKeyId}".toString(),
'settings.s3.endpoint' : "${S3_SERVICE.endpoint}".toString(),
'settings.s3.bucket' : "${DEFAULT_BUCKET}".toString(),
'settings.s3.accounts-dir' : "${S3Service.DEFAULT_ACCOUNT_DIR}".toString(),
'settings.s3.stored-imps-dir' : "${S3Service.DEFAULT_IMPS_DIR}".toString(),
'settings.s3.stored-requests-dir' : "${S3Service.DEFAULT_REQUEST_DIR}".toString(),
'settings.s3.stored-responses-dir': "${S3Service.DEFAULT_RESPONSE_DIR}".toString(),
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove redundant .toString()

Suggested change
protected static Map<String, String> s3StorageConfig = [
'settings.s3.accessKeyId' : "${S3_SERVICE.accessKeyId}".toString(),
'settings.s3.secretAccessKey' : "${S3_SERVICE.secretKeyId}".toString(),
'settings.s3.endpoint' : "${S3_SERVICE.endpoint}".toString(),
'settings.s3.bucket' : "${DEFAULT_BUCKET}".toString(),
'settings.s3.accounts-dir' : "${S3Service.DEFAULT_ACCOUNT_DIR}".toString(),
'settings.s3.stored-imps-dir' : "${S3Service.DEFAULT_IMPS_DIR}".toString(),
'settings.s3.stored-requests-dir' : "${S3Service.DEFAULT_REQUEST_DIR}".toString(),
'settings.s3.stored-responses-dir': "${S3Service.DEFAULT_RESPONSE_DIR}".toString(),
]
protected static Map<String, String> s3StorageConfig = [
'settings.s3.accessKeyId' : s3Service.accessKeyId,
'settings.s3.secretAccessKey' : s3Service.secretKeyId,
'settings.s3.endpoint' : s3Service.endpoint,
'settings.s3.bucket' : DEFAULT_BUCKET,
'settings.s3.accounts-dir' : S3Service.DEFAULT_ACCOUNT_DIR,
'settings.s3.stored-imps-dir' : S3Service.DEFAULT_IMPS_DIR,
'settings.s3.stored-requests-dir' : S3Service.DEFAULT_IMPS_DIR,
'settings.s3.stored-responses-dir': S3Service.DEFAULT_IMPS_DIR,
]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

assert exception.responseBody == "Account $accountId is inactive"
}

def "PBS should throw exception when account have different id inside json in S3 storage"() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

PBS should throw exception when account id is't match wiht bid request account id
Please check other similar case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@osulzhenko
Copy link
Collaborator Author

First of all: kudos to the structure of your functional tests. Super comfortable to read and understand. Even though most of them look like they could be unit tests 😄

3 of the 4 failing tests make totally sense. The one with .secure property I don't get, because I'm not familiar with this feature and what the intention is.

My question is: Do you have the capacity to add the missing checks to make the tests green?

@muuki88 It’s possible to add the missing checks here to make the tests pass. However, for more consistency, I suggest adding these checks in your Pull Request (PR). Once done, I can merge them with the current PR.

marki1an
marki1an previously approved these changes Dec 21, 2023
@muuki88
Copy link
Contributor

muuki88 commented Jan 22, 2024

@SerhiiNahornyi , @marki1an I need to push back on some of the failing tests, as they are currently very hard to implement.

The StoredDataResult model contains the results untyped. So this validation is currently not available in any ApplicationSettings implementation (FilesystemSettings, JdbcSettings).

I would argue that these kind of validations should be done in a generic way a level higher. Could you remove the failing tests?

@marki1an
Copy link
Collaborator

@SerhiiNahornyi , @marki1an I need to push back on some of the failing tests, as they are currently very hard to implement.

The StoredDataResult model contains the results untyped. So this validation is currently not available in any ApplicationSettings implementation (FilesystemSettings, JdbcSettings).

I would argue that these kind of validations should be done in a generic way a level higher. Could you remove the failing tests?

@muuki88 Hi there.
Sure, we'll mark those tests with @PedningFeature annotation, and those tests will skip while annotation present.
@osulzhenko Can you mark those tests?

@osulzhenko
Copy link
Collaborator Author

osulzhenko commented Jan 24, 2024

@SerhiiNahornyi , @marki1an I need to push back on some of the failing tests, as they are currently very hard to implement.
The StoredDataResult model contains the results untyped. So this validation is currently not available in any ApplicationSettings implementation (FilesystemSettings, JdbcSettings).
I would argue that these kind of validations should be done in a generic way a level higher. Could you remove the failing tests?

@muuki88 Hi there. Sure, we'll mark those tests with @PedningFeature annotation, and those tests will skip while annotation present. @osulzhenko Can you mark those tests?

@muuki88 sure, marked

@muuki88
Copy link
Contributor

muuki88 commented Jan 25, 2024

@osulzhenko anything that blocks this?

@osulzhenko
Copy link
Collaborator Author

@osulzhenko anything that blocks this?

@muuki88 Not from my side. You need to get approval on your original PR #2733

@Net-burst
Copy link
Collaborator

The workflow still fails on S3 unit tests:

Error:  Errors: 
Error:    S3ApplicationSettingsTest.getStoredDataReturnsErrorsForNotFoundImpressions:359 » Sdk
Error:    S3ApplicationSettingsTest.getStoredDataReturnsErrorsForNotFoundRequests:329 » Sdk
Error:    S3ApplicationSettingsTest.getStoredDataShouldReturnFetchedStoredImpression » ClassCast
Error:    S3ApplicationSettingsTest.getStoredDataShouldReturnFetchedStoredImpressionAndStoredRequest » ClassCast
Error:    S3ApplicationSettingsTest.getStoredDataShouldReturnFetchedStoredImpressionWithAdUnitPathStoredId » ClassCast
Error:    S3ApplicationSettingsTest.getStoredDataShouldReturnFetchedStoredRequest » ClassCast
[INFO] 
Error:  Tests run: 7271, Failures: 0, Errors: 6, Skipped: 0

…nctional-tests

# Conflicts:
#	pom.xml
#	src/test/groovy/org/prebid/server/functional/testcontainers/Dependencies.groovy
@osulzhenko osulzhenko requested a review from marki1an August 23, 2024 07:11
@Compile-Ninja Compile-Ninja changed the base branch from master to s3-application-settings/copy September 3, 2024 09:41
@Compile-Ninja Compile-Ninja merged commit 65d28dc into s3-application-settings/copy Sep 3, 2024
@Compile-Ninja Compile-Ninja deleted the s3-settings-functional-tests branch September 3, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Functional or other tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants