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

feat(iota-indexer): Refactor ExtendedApi tests in indexer to use shared test cluster #3018

Conversation

tomxey
Copy link
Contributor

@tomxey tomxey commented Oct 2, 2024

Description of change

Introduce shared simulacrum cluster, to use in extended api tests.

With this PR execution of all tests in iota-indexer takes 30 seconds.

With this change the tests are using shared_test_indexer_db for tests with shared cluster, simulacrum_env_db_extended_api for extended_api tests with shared simulacrum and indexer_ingestion_tests_db for ingestion tests in iota-indexer.

Test indexer reader is always run on some free port, instead of a hardcoded one.

Simulacrum fullnode rpc api is run on free port by default, instead of hardcoded one.

In general it allows to have several simulacrum envs and indexers to be running next to each other without conflict.

Links to any relevant issues

fixes #2951

Type of change

  • Enhancement (a non-breaking change which adds functionality)

How the change has been tested

cargo test --profile simulator --features shared_test_runtime --test rpc-tests

cargo test --profile simulator --features pg_integration --test ingestion_tests -- --test-threads=1

Change checklist

Tick the boxes that are relevant to your changes, and delete any items that are not.

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that new and existing unit tests pass locally with my changes

@tomxey tomxey changed the base branch from develop to sc-platform/indexer-new-rpc-tests October 2, 2024 14:33
@tomxey tomxey force-pushed the sc-platform/refactor-extended-api-tests-to-use-shared-runtime branch 5 times, most recently from e0539ec to 6658ad6 Compare October 10, 2024 13:57
@tomxey tomxey marked this pull request as ready for review October 10, 2024 14:04
@tomxey tomxey requested review from a team as code owners October 10, 2024 14:04
@tomxey tomxey self-assigned this Oct 10, 2024
@sergiupopescu199 sergiupopescu199 self-requested a review October 15, 2024 10:31
@sergiupopescu199 sergiupopescu199 self-requested a review October 15, 2024 10:58
crates/iota-indexer/src/test_utils.rs Outdated Show resolved Hide resolved
crates/iota-indexer/tests/common/mod.rs Outdated Show resolved Hide resolved
crates/iota-indexer/tests/common/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@sergiupopescu199 sergiupopescu199 left a comment

Choose a reason for hiding this comment

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

lgtm ✨

Copy link
Contributor

@kodemartin kodemartin 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 @tomxey

Left a few comments because I think it can be simplified

@@ -58,10 +63,47 @@ impl ApiTestSetup {
}
}

pub struct SimulacrumApiTestEnvDefinition {
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it hard to reason about the semantics and the necessity of this type.

Why not initializing directly the InitializedSimulacrumEnv passing a Simulacrum value and not a closure that produces it?

Copy link
Contributor Author

@tomxey tomxey Oct 24, 2024

Choose a reason for hiding this comment

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

The reason was that originally I wanted to make instances of this type global, have the initialized env also stored inside of it, and initialize env like:

let ... = env_definition_instance.get_or_init()

To better show that all the params and the env are tied together.

I lost a fight with the Rust ownership checking system and couldn't make such variable global though.

Finally I settled with approach where the coupling is 'guaranteed' by having a dedicated function for every environment. In this case this type is really not needed I think. I will proceed with removing it.

Having the closure that produces the Simulacrum value it is possible for initialization to happen only once, in case the env already exists then the closure is just not called. It seems cleaner that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pub env_initializer: Box<dyn Fn() -> Simulacrum>,
}

pub struct InitializedSimulacrumEnv {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is a bit confusing to me. With this present it would seem plausible to me to have two setups:

  1. ApiTestSetup -> ClusterTestSetup
  2. SimulacrumTestSetup
Suggested change
pub struct InitializedSimulacrumEnv {
pub struct ClusterTestSetup {

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 think we can rename to SimulacrumTestSetup.

This name was like this to distinguish the already Initialized env from the EnvDefinition that is yet to be initialized. But since we are removing the SimulacrumApiTestEnvDefinition type we can also rename this one to something simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tomxey tomxey requested a review from kodemartin October 24, 2024 15:05
@tomxey tomxey force-pushed the sc-platform/refactor-extended-api-tests-to-use-shared-runtime branch from 5d26c9c to c81f663 Compare October 28, 2024 11:48
@tomxey tomxey requested review from a team as code owners October 28, 2024 11:48
@tomxey tomxey removed request for a team October 28, 2024 15:16
@tomxey tomxey marked this pull request as draft October 28, 2024 15:16
@tomxey tomxey force-pushed the sc-platform/refactor-extended-api-tests-to-use-shared-runtime branch 4 times, most recently from 3e109c6 to e56aaa5 Compare October 29, 2024 09:35
@tomxey tomxey marked this pull request as ready for review October 29, 2024 09:38
Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: e56aaa5

✅ Preview: https://apps-ui-qiuohxype-iota1.vercel.app

Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: e56aaa5

✅ Preview: https://iota-rebased-explorer-092603f1de8088243ccb8b861b23e-ez1hbggqy.vercel.app

Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: e56aaa5

✅ Preview: https://apps-backend-29a719c9ccbdb9b80c97b599a599d8953354da-9j454sddn.vercel.app

Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: e56aaa5

✅ Preview: https://wallet-dashboard-a225fcfa1e2f852205a61a7cd1d5d93e92-c3fbw7tnz.vercel.app

@@ -4,7 +4,7 @@
#[allow(dead_code)]
#[path = "../common/mod.rs"]
mod common;
#[cfg(feature = "pg_integration")]
#[cfg(feature = "shared_test_runtime")]
Copy link
Member

Choose a reason for hiding this comment

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

I think in the README.md we have some outdated instructions on how to run the tests. Could you please update them too? 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, doesn't need to be adjustment in the readme

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted readme to use --test-threads=1.

@tomxey tomxey force-pushed the sc-platform/refactor-extended-api-tests-to-use-shared-runtime branch from e56aaa5 to f796733 Compare October 29, 2024 14:45
Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: f796733

✅ Preview: https://apps-ui-ha2v8ohpa-iota1.vercel.app

Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: f796733

✅ Preview: https://apps-backend-29a719c9ccbdb9b80c97b599a599d8953354da-mavt18c4y.vercel.app

@tomxey tomxey merged commit d08f374 into sc-platform/indexer-new-rpc-tests Oct 29, 2024
22 of 27 checks passed
@tomxey tomxey deleted the sc-platform/refactor-extended-api-tests-to-use-shared-runtime branch October 29, 2024 14:49
Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: f796733

✅ Preview: https://iota-rebased-explorer-092603f1de8088243ccb8b861b23e-nuo5y05gw.vercel.app

Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: f796733

✅ Preview: https://wallet-dashboard-a225fcfa1e2f852205a61a7cd1d5d93e92-5hxaoftzo.vercel.app

sergiupopescu199 pushed a commit that referenced this pull request Oct 31, 2024
…ed test cluster (#3018)

* feat(iota-indexer): Refactor ExtendedApi tests in indexer to use shared test cluster

* Reuse function for finding available port/socket

* Get rid of the `replace_db_name` function

* Use &str instad of String for database_name where possible

* Remove SimulacrumApiTestEnvDefinition type, rename InitializedSimulacrumEnv type

* Fixes after rebase on recent feature branch

* Update README to run tests with `--test-threads 1`
sergiupopescu199 pushed a commit that referenced this pull request Oct 31, 2024
…ed test cluster (#3018)

* feat(iota-indexer): Refactor ExtendedApi tests in indexer to use shared test cluster

* Reuse function for finding available port/socket

* Get rid of the `replace_db_name` function

* Use &str instad of String for database_name where possible

* Remove SimulacrumApiTestEnvDefinition type, rename InitializedSimulacrumEnv type

* Fixes after rebase on recent feature branch

* Update README to run tests with `--test-threads 1`
sergiupopescu199 pushed a commit that referenced this pull request Oct 31, 2024
…ed test cluster (#3018)

* feat(iota-indexer): Refactor ExtendedApi tests in indexer to use shared test cluster

* Reuse function for finding available port/socket

* Get rid of the `replace_db_name` function

* Use &str instad of String for database_name where possible

* Remove SimulacrumApiTestEnvDefinition type, rename InitializedSimulacrumEnv type

* Fixes after rebase on recent feature branch

* Update README to run tests with `--test-threads 1`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Issues related to the Infrastructure Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task (Infrastructure)]: Refactor ExtendedApi tests to use the shared cluster
5 participants