-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feat : add testing fixtures and a basic test #52
Conversation
ocdbytes
commented
Jul 23, 2024
- Added local stack s3 bucket mocking tests for putting and getting the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments and questions. Mostly, you should document the intent of your tests and use fixtures to clean up the DB.
crates/orchestrator/src/config.rs
Outdated
match get_env_var_or_panic("DATA_STORAGE").as_str() { | ||
"s3" => Box::new(AWSS3::new(AWSS3Config::new_from_env()).await), | ||
_ => panic!("Unsupported Storage Client"), | ||
} | ||
} | ||
|
||
#[cfg(test)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: why don't you put this in a dedicated module to avoid annotating every item with #[cfg(test)]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid, Moved this code to a orchestrator/src/tests/config.rs
No need to feature flag now.
crates/orchestrator/src/config.rs
Outdated
self.settlement_client.unwrap(), | ||
self.database.unwrap(), | ||
self.queue.unwrap(), | ||
self.storage.unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid these unwraps, a better pattern is to do, for each entry (example with prover_client
):
let prover_client = self.prover_client.unwrap_or_else(|| build_prover_service(&settings_provider));
and then just pass prover_client
to Config::new()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid, unwrap_or_else
can readily be used for prover_client
for better code pattern.
Upon further inspection :
- settlement_client
- storage_client
- da_client
- database
are built usingasync build functions
which makes it tricky to create usingunwrap_or_else
.
We can write something like :
use tokio::runtime::Handle;
// ...
self.settlement_client = Some(self.settlement_client.unwrap_or_else(|| {
Handle::current().block_on(build_settlement_client(&settings_provider))
}));
But then we'll have unnecessary runtime overhead.
Proposed Solution :
- change
sync build functions
to useunwrap_or_else
. - handle
async build functions
in separate assignment usingawait
.
WDYT ?
@@ -12,6 +12,9 @@ pub struct AWSS3Config { | |||
pub s3_bucket_name: String, | |||
/// S3 Bucket region | |||
pub s3_bucket_region: String, | |||
/// Endpoint url | |||
#[cfg(test)] | |||
pub endpoint_url: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this only used in tests? Is there no equivalent notion when connecting to AWS directly? It would be better to avoid this difference between production and testing, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Localstack endpoint URL : http://localhost.localstack.cloud:4566
AWS endpoint URL. : https://s3.{region}.amazonaws.com/{bucket-name}/{key}
We are using localstack for mocking AWS locally.
Localstack requires endpoint_url
to get connected.
Connection to AWS doesn't necessarily require the endpoint url as shown here.
Rather, the connection to localstack does as shown here.
Hence this implementation is under the tests flag.
What do you propose as a solution?,
Do you think changing prod code as how tests are written (adding endpoint url on prod just because it's available on tests) is a valid way to go ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But specifying the endpoint is still a possibility on AWS, right? I'm not in favor of "modifying production code", but here it's just that you have 2 different ways of connecting: either you specify the region, bucket key etc or you provide the endpoint directly. It turns out that localstack only supports the endpoint method, sure.
In effect you have two usable connection solutions => you could use an enumeration to support both features, for example giving priority to the endpoint method if someone wants to hardcode it for some reason and then support the default method as a backup. This way, your code is the same for testing vs prod and you support two methods to connect to AWS. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @odesenfans
I agree with your implementation and it is more cleaner. I will implement this and push the code.
@@ -40,6 +40,10 @@ impl MongoDb { | |||
MongoDb { client } | |||
} | |||
|
|||
pub fn client(&self) -> Client { | |||
self.client.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: when I see the call to clone()
, my first reflex is to check the cost of this operation. I looked at the docs of MongoDB and saw that Client
uses an Arc
internally, so this is fine. But it is worth adding a comment explaining why this is fine, because for non Arc-based types doing
pub fn client(&self) -> &Client {
&self.client
}
and then letting the caller decide if he wants to clone is better.
TL;DR, add a comment to explain that Client
uses Arc
and therefore is cheap to clone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid and a great catch,
added docs to describe that client
uses Arc
.
.nest("/v1/dev", dev_routes()) | ||
.nest("/v1/job", job_routes()) | ||
.fallback(handler_404) | ||
Router::new().route("/health", get(root)).nest("/v1/dev", dev_routes()).fallback(handler_404) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this change related to the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a valid concern,
While the tests for Job_controller
were being written it was realised that we are not using it anymore and hence it can be deleted, we agree, ideally this is to be done on a separate PR.
Proposed Solution :
- Have stricter decouples of PR from next time.
- Keep the commit with this PR.
- Mention removal of
job_controller
in theCHANGELOG
.
WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep it in this PR, but mention it in the changelog and in the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
pub async fn drop_database() -> color_eyre::Result<()> { | ||
let db_client: Client = MongoDb::new(MongoDbConfig::new_from_env()).await.client(); | ||
// dropping `jobs` collection. | ||
db_client.database("orchestrator").collection::<JobItem>("jobs").drop(None).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful that you'll need to add every future collection in here as well. It might be better to just drop every collection under the orchestrator
DB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid, changed to dropping all the collections for now.
- Added comment to how to change to specific collection.
|
||
#[rstest] | ||
#[tokio::test] | ||
async fn test_put_and_get_data_s3() -> color_eyre::Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a sanity check to see that putting and getting to/from S3 is working, right? Don't hesitate to document what your tests intend to do, that helps for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid, Added docs for this test.
TestConfigBuilder::new().build().await; | ||
|
||
drop_database().await.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a fixture to start with a fresh DB and an already built config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid,
We had used fixture
in the initial stages of tests but we soon realised that we require more customisability like mocking only da_client
while writing tests, hence we went with the Builder Design Pattern to achieve the same.
Moreover :
drop_database
is an async fn, we didn't find this to be a valid enough reason to implementDrop
on Config.
Proposed Solution :
- we add
drop_database
as a part ofTestConfigBuilder.build()
so that we drop the database once before each test-case runs, which gives same result as dropping database after each test-case.
WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several things to say here.
- Regarding when to drop the DB, I believe it's best to drop it when the test starts and not after it finishes. This way, you can inspect the DB to understand what went wrong.
- Fixture vs manual call: While you're going to have multiple test configs, you're only going to use a few. So defining a few fixtures with the right configuration options on the test builder that return the test config is probably the right thing to do. This enables finer-grained control on when to reset the DB (once for a group of tests? For each test?) depending on what you want.
- We didn't talk about test concurrency here, but if you let all your tests execute in parallel you have a strong risk of dropping the DB in the middle of another test. Do you have a solution for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Yes so we will do that in the beginning of the tests only.
- Will have to think about that can you give me an example on this if possible ?
- We were also discussing about this few days back. We will have to come up on this solution but currently we don't have one yet. We were thinking to make collections test wise or databases for different tests something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add on (3), the major blocker for concurrency would be DB or AWS localstack. We haven't finalized the implementation yet but it shouldn't be difficult to add on the current implementation. As @ocdbytes mentioned, we were looking at mostly using different databases for each test case and different localstack accounts. I think the changes should be localized to the builder itself but the idea was to focus on this more when we see test cases taking >15mins or so. wdyt?
…p all collections not just jobs
@@ -40,6 +40,13 @@ impl MongoDb { | |||
MongoDb { client } | |||
} | |||
|
|||
/// Mongodb client uses Arc internally, reducing the cost of clone. | |||
/// Directly using clone is not recommended for libraries not using Arc internally. | |||
/// Dev might want to pass an Arc manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what "Dev might want to pass an Arc manually." means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove this comment : "Dev might want to pass an Arc manually.". It may create confusion for someone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smol review
Co-authored-by: 0xevolve <Artevolve@yahoo.com>
* feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : updated test config and added config type to aws s3 config * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * feat : lint fix * fix : coverage tests fix * fix : test fix --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com>
* feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : updated test config and added config type to aws s3 config * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * feat : lint fix * fix : coverage tests fix * fix : test fix --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com>
* feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : updated test config and added config type to aws s3 config * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * feat : lint fix * fix : coverage tests fix * fix : test fix --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com>
* feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : updated test config and added config type to aws s3 config * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * feat : lint fix * fix : coverage tests fix * fix : test fix --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com>
* feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : updated test config and added config type to aws s3 config * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * feat : lint fix * fix : coverage tests fix * fix : test fix --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com>
* feat: Aptos Settelement Layer (#7) * feat(aptos_settlement_client): update state kzg & update state & verify inclusion * test(aptos_settlement_client): add update_state, state_block_number unit test * fix: dependencies * refactor code * feat: add submodule ionia * feat(aptos_settlement_client): update state kzg & update state & verify inclusion * test(aptos_settlement_client): add update_state, state_block_number unit test * fix: dependencies * refactor code * feat: add submodule ionia * refactor code * refactor code --------- Co-authored-by: Steve Nguyen <sonntuet1997@gmail.com> * feat: pull request template * Bump ionia from `3a15977` to `fe4cd5a` (#10) Bumps [ionia](https://github.com/sota-zk-labs/ionia) from `3a15977` to `fe4cd5a`. - [Commits](sota-zk-labs/ionia@3a15977...fe4cd5a) --- updated-dependencies: - dependency-name: ionia dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: Aptos Da Client * feat: Data Submission Worker Integration. (madara-alliance#51) * update: DA job draft #1 * docs: changelog updated * update: is_worker_enabled impl & usage in da_submission, removal of String from VerificationFailed * update: renamed to * update: run worker only if it's enabled using is_worker_enabled check * build: linter fixes * Update CHANGELOG.md Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> * update: limit_to_one on get_jobs_by_status * update: removed get_last_successful_job_by_type, added get_latest_job_by_type_and_status * update: added error to job metadata * update: pr resolution, simplifying get_jobs_by_status, rejected status in verify_jobs * update: linting fixes * Update crates/orchestrator/src/jobs/mod.rs Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> * update: removing .expect from mongodb mod file * update: fixed testcase for snos worker * chore: correct variable name * update: added support to check againt multiple status - is_worker_enabled, get_jobs_by_statuses * docs: rewrote 1 job per block assumption * docs: DataSubmissionWorker -> DataAvailabilitySynchronizer * chore: liniting fix * update: changed name : DataAvailabilitySynchronizer -> DataSubmissionWorker --------- Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> * Feat : add testing fixtures and a basic test (madara-alliance#52) * feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : updated test config and added config type to aws s3 config * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * feat : lint fix * fix : coverage tests fix * fix : test fix --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com> * Feat : job handler tests (madara-alliance#67) * feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : create job test case error returning * mock job handler * feat : added jobs test and modified worker tests * feat : added queue checks to tests and revamped some tests * feat : updated tests and resolved comments * feat : updated test config and added config type to aws s3 config * feat : updated tests and test names * feat : lint fixes * feat : lint fixes * feat : lint fixes * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * chore : lint fixes * feat : lint fix * fix : coverage tests fix * fix : test fix * fix : updated region in localstack .env.test * feat : updated region * debug : added debug log to github ci * feat : updated queue code for test fixes * fix : sqs region fix * debug : added debug logs for ci debugging * feat : added override endpoint to queue url in producer and consumer * feat : added override endpoint to queue url in producer and consumer * fix : removed logs and refactored the code * chore : refactor code --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Steve Nguyen <sonntuet1997@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> Co-authored-by: Arun Jangra <arunjangra1001@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com>
* feat : added tests for increasing coverage * feat : added mongo db tests and fixtures and updated the ci for tests * update : removed unwanted fixtures * update : removed unwanted fixtures * update : added mongo db runner in ci * update : added mongo db runner in ci * update : added mongo db runner in ci * update : updated with new changes and ci * update : updated test cases for s3 client * update : added .env.test file in the commit * feat : added database necessary tests * feat : added database necessary tests * Revert "feat : added database necessary tests" This reverts commit 65d66e6. * Revert "feat : added database necessary tests" This reverts commit 906a1eb. * update: Replaced Build_Config Fixture with TestConfigBuilder * update : config update * update : test_put_and_get_data_s3 test * update: moved testconfigbuilder to tests/config.rs & added docs , drop all collections not just jobs * feat : updated test config and added config type to aws s3 config * chore: resolved pr comments * Update crates/orchestrator/src/tests/database/mod.rs Co-authored-by: 0xevolve <Artevolve@yahoo.com> * feat : lint fix * fix : coverage tests fix * fix : test fix --------- Co-authored-by: Heemank Verma <heemankv@gmail.com> Co-authored-by: 0xevolve <Artevolve@yahoo.com>