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

chore(IDX): introduce the pocket_ic_test macro #3268

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
32 changes: 32 additions & 0 deletions bazel/pocket-ic-tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,35 @@ pocket_ic_mainnet_test = rule(
executable = True,
test = True,
)

def pocket_ic_test(name, test_rule, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not too fond of small macros that just wrap a target and inject dependencies; I find they tend to add complexity and obfuscate what is really happening, making everything harder to follow and debug, especially when e.g. the test_rule needs to be specified.

Is the goal here mostly to avoid repetition? Do we have a ticket we can link to re. the sandbox issue on Darwin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Context is in this thread. I would like to have a central place where we do work-arounds for that sandbox issue on darwin and not scatter it all over our code base.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see; agree it's a good idea to have a central place for the workaround but I don't think this requires implicitly injecting pocket-ic. How about modifying rust_ic_test to add requires-network if pocket-ic is a dependency?

Also, can you add a ticket so that we can track the issue upstream and remove the workaround once it's fixed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about modifying rust_ic_test to add requires-network if pocket-ic is a dependency?

That seems rather hacky and an implicit rule like that could lead to surprises. Also it's not just rust_ic_test that needs to be modified but also rust_test, rust_test_suite and rust_test_suite_with_extra_srcs. Or do they all resolve back to rust_test?

can you add a ticket so that we can track the issue upstream and remove the workaround once it's fixed?

Good idea: https://dfinity.atlassian.net/browse/IDX-3192

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant a ticket upstream on bazel! With just an internal ticket I doubt we'll follow up & make progress on this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems like a similar issue: bazelbuild/bazel#14828. Let me study that a bit more later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There seems to be a work around by using IPv6 instead of IPv4. @mraszyk maybe that's something you can look into.

"""
Runs a test using the pocket-ic-server.

The test will add //rs/pocket_ic_server:pocket-ic-server as a data dependency
and will point the environment variable POCKET_IC_BIN to it.

Args:
name: the name of the test target.
test_rule: which test test rule to use like rust_test, rust_test_suite_with_extra_srcs, etc.
**kwargs: keyword arguments passed to the test_rule.
"""
data = kwargs.pop("data", [])
env = kwargs.pop("env", {})
tags = kwargs.pop("tags", [])
test_rule(
name = name,
data = data + ["//rs/pocket_ic_server:pocket-ic-server"],
env = env | {
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
},
tags = tags + [
# TODO: remove 'requires-network' tag when the root cause for sporadic error below on Apple is identified and fixed.
# Failed to crate http gateway: Failed to bind to address 127.0.0.1:0: Operation not permitted (os error 1)
#
# Ideally we use a condition here to only require the network on darwin
# but conditions are not supported in tags: https://github.com/bazelbuild/bazel/issues/2971.
"requires-network",
],
**kwargs
)
25 changes: 7 additions & 18 deletions packages/pocket-ic/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test", "rust_test_suite")
load("//bazel:pocket-ic-tests.bzl", "pocket_ic_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -68,78 +69,66 @@ rust_test(
deps = [":pocket-ic"] + DEPENDENCIES + TEST_DEPENDENCIES,
)

rust_test_suite(
pocket_ic_test(
name = "test",
size = "medium",
srcs = ["tests/tests.rs"],
data = [
"//packages/pocket-ic/test_canister:test_canister.wasm",
"//rs/pocket_ic_server:pocket-ic-server",
"@mozilla_root_ca_store//file",
],
env = {
"RUST_TEST_THREADS": "2",
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
"SSL_CERT_FILE": "$(rootpath @mozilla_root_ca_store//file)",
"TEST_WASM": "$(rootpath //packages/pocket-ic/test_canister:test_canister.wasm)",
},
flaky = False,
proc_macro_deps = MACRO_DEPENDENCIES,
tags = [
"cpu:16",
# TODO: remove 'requires-network' tag when the root cause for sporadic error below on Apple Silicon is identified and fixed.
# Failed to crate http gateway: Failed to bind to address 127.0.0.1:0: Operation not permitted (os error 1)
"requires-network",
"test_macos",
],
test_rule = rust_test_suite,
deps = [":pocket-ic"] + DEPENDENCIES + TEST_DEPENDENCIES,
)

rust_test_suite(
pocket_ic_test(
name = "restart",
size = "medium",
srcs = ["tests/restart.rs"],
data = [
"//rs/pocket_ic_server:pocket-ic-server",
"@mozilla_root_ca_store//file",
],
env = {
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
"SSL_CERT_FILE": "$(rootpath @mozilla_root_ca_store//file)",
},
flaky = False,
proc_macro_deps = MACRO_DEPENDENCIES,
tags = [
# TODO: remove 'requires-network' tag when the root cause for sporadic error below on Apple Silicon is identified and fixed.
# Failed to crate http gateway: Failed to bind to address 127.0.0.1:0: Operation not permitted (os error 1)
"requires-network",
"test_macos",
],
test_rule = rust_test_suite,
deps = [":pocket-ic"] + DEPENDENCIES + TEST_DEPENDENCIES,
)

rust_test_suite(
pocket_ic_test(
name = "slow",
size = "medium",
srcs = ["tests/slow.rs"],
data = [
"//packages/pocket-ic/test_canister:test_canister.wasm",
"//rs/pocket_ic_server:pocket-ic-server",
"@mozilla_root_ca_store//file",
],
env = {
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
"SSL_CERT_FILE": "$(rootpath @mozilla_root_ca_store//file)",
"TEST_WASM": "$(rootpath //packages/pocket-ic/test_canister:test_canister.wasm)",
},
flaky = False,
proc_macro_deps = MACRO_DEPENDENCIES,
tags = [
"cpu:16",
# TODO: remove 'requires-network' tag when the root cause for sporadic error below on Apple Silicon is identified and fixed.
# Failed to crate http gateway: Failed to bind to address 127.0.0.1:0: Operation not permitted (os error 1)
"requires-network",
"test_macos",
],
test_rule = rust_test_suite,
deps = [":pocket-ic"] + DEPENDENCIES + TEST_DEPENDENCIES,
)
6 changes: 3 additions & 3 deletions rs/bitcoin/checker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test")
load("//bazel:pocket-ic-tests.bzl", "pocket_ic_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -81,7 +82,7 @@ rust_canister(
],
)

rust_ic_test(
pocket_ic_test(
name = "integration_tests",
srcs = ["tests/tests.rs"],
data = [
Expand All @@ -91,13 +92,12 @@ rust_ic_test(
env = {
"CARGO_MANIFEST_DIR": "rs/bitcoin/checker",
"IC_BTC_CHECKER_CANISTER_WASM_PATH": "$(rootpath :btc_checker_canister)",
"POCKET_IC_BIN": "$(rootpath //:pocket-ic-server)",
"UNIVERSAL_CANISTER_WASM_PATH": "$(rootpath //rs/universal_canister/impl:universal_canister.wasm.gz)",
},
test_rule = rust_ic_test,
deps = [
# Keep sorted.
":btc_checker_lib",
"//:pocket-ic-server",
"//packages/pocket-ic",
"//rs/rust_canisters/http_types",
"//rs/test_utilities/load_wasm",
Expand Down
6 changes: 3 additions & 3 deletions rs/boundary_node/rate_limits/integration_tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_rust//rust:defs.bzl", "rust_library")
load("//bazel:defs.bzl", "rust_test_suite_with_extra_srcs")
load("//bazel:pocket-ic-tests.bzl", "pocket_ic_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -36,15 +37,13 @@ ALIASES = {}
DEV_DATA = [
"@mainnet_nns_registry_canister//file",
"//rs/registry/canister:registry-canister",
"//rs/pocket_ic_server:pocket-ic-server",
"//rs/boundary_node/rate_limits:rate_limit_canister",
]

DEV_ENV = {
"CARGO_MANIFEST_DIR": "rs/nns/integration_tests",
"REGISTRY_CANISTER_WASM_PATH": "$(rootpath //rs/registry/canister:registry-canister)",
"MAINNET_REGISTRY_CANISTER_WASM_PATH": "$(rootpath @mainnet_nns_registry_canister//file)",
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
"RATE_LIMITS_CANISTER_WASM_PATH": "$(rootpath //rs/boundary_node/rate_limits:rate_limit_canister)",
}

Expand All @@ -58,7 +57,7 @@ rust_library(
deps = DEPENDENCIES,
)

rust_test_suite_with_extra_srcs(
pocket_ic_test(
name = "integration_tests_test",
srcs = glob(
["tests/**/*.rs"],
Expand All @@ -70,5 +69,6 @@ rust_test_suite_with_extra_srcs(
flaky = False,
proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
tags = [],
test_rule = rust_test_suite_with_extra_srcs,
deps = [":rate_limit_canister_integration_tests"] + DEPENDENCIES + DEV_DEPENDENCIES,
)
6 changes: 3 additions & 3 deletions rs/ledger_suite/icp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:candid.bzl", "did_git_test")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test_suite")
load("//bazel:pocket-ic-tests.bzl", "pocket_ic_test")
load("//bazel:prost.bzl", "generated_files_check")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -90,7 +91,7 @@ rust_canister(
],
)

rust_ic_test_suite(
pocket_ic_test(
name = "ledger_canister_integration_test",
timeout = "long",
srcs = [
Expand All @@ -106,7 +107,6 @@ rust_ic_test_suite(
"//rs/ledger_suite/icp/index:ic-icp-index-canister",
"//rs/ledger_suite/icp/ledger:ledger-canister-wasm",
"//rs/ledger_suite/icp/ledger:ledger-canister-wasm-notify-method",
"//rs/pocket_ic_server:pocket-ic-server",
"@mainnet_icp_index_canister//file",
"@mainnet_icp_ledger-archive-node-canister//file",
"@mainnet_icp_ledger_canister//file",
Expand All @@ -121,9 +121,9 @@ rust_ic_test_suite(
"MAINNET_ICP_INDEX_CANISTER_WASM_PATH": "$(rootpath @mainnet_icp_index_canister//file)",
"MAINNET_ICP_LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(rootpath @mainnet_icp_ledger-archive-node-canister//file)",
"MAINNET_ICP_LEDGER_CANISTER_WASM_PATH": "$(rootpath @mainnet_icp_ledger_canister//file)",
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
"TEST_NOTIFIED_WASM_PATH": "$(rootpath :test_notified_canister)",
},
test_rule = rust_ic_test_suite,
deps = [
# Keep sorted.
":icp_ledger",
Expand Down
6 changes: 3 additions & 3 deletions rs/ledger_suite/icp/archive/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_rust//rust:defs.bzl", "rust_test")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test")
load("//bazel:pocket-ic-tests.bzl", "pocket_ic_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -48,18 +49,17 @@ rust_test(
deps = ["@crate_index//:candid_parser"],
)

rust_ic_test(
pocket_ic_test(
name = "ledger_archive_node_canister_integration",
srcs = ["tests/tests.rs"],
data = [
"//rs/ledger_suite/icp/archive:ledger-archive-node-canister-wasm",
"//rs/pocket_ic_server:pocket-ic-server",
],
env = {
"CARGO_MANIFEST_DIR": "rs/ledger_suite/icp/archive",
"LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(rootpath //rs/ledger_suite/icp/archive:ledger-archive-node-canister-wasm)",
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
},
test_rule = rust_ic_test,
deps = [
# Keep sorted.
"//packages/pocket-ic",
Expand Down
21 changes: 13 additions & 8 deletions rs/nervous_system/integration_tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:defs.bzl", "rust_test_suite_with_extra_srcs")
load("//bazel:pocket-ic-tests.bzl", "pocket_ic_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -93,7 +94,6 @@ DEV_DATA = [
"//rs/nns/gtc:genesis-token-canister",
"//rs/nns/handlers/root/impl:root-canister",
"//rs/nns/sns-wasm:sns-wasm-canister",
"//rs/pocket_ic_server:pocket-ic-server",
"//rs/registry/canister:registry-canister",
"//rs/rosetta-api/tvl/xrc_mock:xrc_mock_canister",
"//rs/sns/governance:sns-governance-canister-test",
Expand Down Expand Up @@ -147,7 +147,6 @@ DEV_ENV = {
"MAINNET_SNS_SWAP_CANISTER_WASM_PATH": "$(rootpath @mainnet_sns-swap-canister//file)",
"ROOT_CANISTER_WASM_PATH": "$(rootpath //rs/nns/handlers/root/impl:root-canister)",
"XRC_MOCK_WASM_PATH": "$(rootpath //rs/rosetta-api/tvl/xrc_mock:xrc_mock_canister)",
"POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
"UNIVERSAL_CANISTER_WASM_PATH": "$(rootpath //rs/universal_canister/impl:universal_canister.wasm.gz)",
}

Expand All @@ -162,7 +161,7 @@ rust_library(
deps = DEPENDENCIES_WITH_TEST_FEATURES,
)

rust_test_suite_with_extra_srcs(
pocket_ic_test(
name = "integration_tests_test",
timeout = "long",
srcs = glob(
Expand All @@ -189,10 +188,11 @@ rust_test_suite_with_extra_srcs(
tags = [
"cpu:6",
],
test_rule = rust_test_suite_with_extra_srcs,
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
)

rust_test(
pocket_ic_test(
name = "upgrade_everything_test",
timeout = "long",
srcs = [
Expand All @@ -208,10 +208,11 @@ rust_test(
tags = [
"cpu:6",
],
test_rule = rust_test,
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
)

rust_test(
pocket_ic_test(
name = "advance_target_version_upgrades_all_canisters_test",
timeout = "long",
srcs = [
Expand All @@ -225,10 +226,11 @@ rust_test(
tags = [
"cpu:4",
],
test_rule = rust_test,
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
)

rust_test(
pocket_ic_test(
name = "upgrade_existing_sns_test",
timeout = "long",
srcs = [
Expand All @@ -242,10 +244,11 @@ rust_test(
tags = [
"cpu:4",
],
test_rule = rust_test,
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
)

rust_test(
pocket_ic_test(
name = "deploy_fresh_sns_test",
timeout = "long",
srcs = [
Expand All @@ -259,10 +262,11 @@ rust_test(
tags = [
"cpu:4",
],
test_rule = rust_test,
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
)

rust_test(
pocket_ic_test(
name = "sns_release_qualification_legacy",
timeout = "long",
srcs = [
Expand All @@ -277,5 +281,6 @@ rust_test(
tags = [
"cpu:4",
],
test_rule = rust_test,
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
)
Loading
Loading