2026-01-16 21:47:59 +11:00
|
|
|
import std/httpclient
|
2023-06-22 20:32:18 +10:00
|
|
|
import std/os
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
import std/sequtils
|
|
|
|
|
import std/strutils
|
|
|
|
|
import std/sugar
|
|
|
|
|
import std/times
|
2024-03-12 10:57:13 +01:00
|
|
|
import pkg/codex/conf
|
feat: create logging proxy (#663)
* implement a logging proxy
The logging proxy:
- prevents the need to import chronicles (as well as export except toJson),
- prevents the need to override `writeValue` or use or import nim-json-seralization elsewhere in the codebase, allowing for sole use of utils/json for de/serialization,
- and handles json formatting correctly in chronicles json sinks
* Rename logging -> logutils to avoid ambiguity with common names
* clean up
* add setProperty for JsonRecord, remove nim-json-serialization conflict
* Allow specifying textlines and json format separately
Not specifying a LogFormat will apply the formatting to both textlines and json sinks.
Specifying a LogFormat will apply the formatting to only that sink.
* remove unneeded usages of std/json
We only need to import utils/json instead of std/json
* move serialization from rest/json to utils/json so it can be shared
* fix NoColors ambiguity
Was causing unit tests to fail on Windows.
* Remove nre usage to fix Windows error
Windows was erroring with `could not load: pcre64.dll`. Instead of fixing that error, remove the pcre usage :)
* Add logutils module doc
* Shorten logutils.formatIt for `NBytes`
Both json and textlines formatIt were not needed, and could be combined into one formatIt
* remove debug integration test config
debug output and logformat of json for integration test logs
* Use ## module doc to support docgen
* bump nim-poseidon2 to export fromBytes
Before the changes in this branch, fromBytes was likely being resolved by nim-stew, or other dependency. With the changes in this branch, that dependency was removed and fromBytes could no longer be resolved. By exporting fromBytes from nim-poseidon, the correct resolution is now happening.
* fixes to get compiling after rebasing master
* Add support for Result types being logged using formatIt
2024-01-23 18:35:03 +11:00
|
|
|
import pkg/codex/logutils
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
import pkg/chronos/transports/stream
|
2024-03-12 10:57:13 +01:00
|
|
|
import pkg/questionable
|
|
|
|
|
import ./codexconfig
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
import ./codexprocess
|
2024-03-12 10:57:13 +01:00
|
|
|
import ./nodeconfigs
|
2026-01-16 21:47:59 +11:00
|
|
|
import ./utils
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
import ../asynctest
|
|
|
|
|
import ../checktest
|
2023-06-22 20:32:18 +10:00
|
|
|
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
export asynctest
|
|
|
|
|
export codexprocess
|
|
|
|
|
export codexconfig
|
2025-02-20 16:52:51 +11:00
|
|
|
export nodeconfigs
|
2023-06-22 20:32:18 +10:00
|
|
|
|
2026-01-16 21:47:59 +11:00
|
|
|
{.push raises: [].}
|
|
|
|
|
|
2023-09-13 16:17:56 +02:00
|
|
|
type
|
|
|
|
|
RunningNode* = ref object
|
|
|
|
|
role*: Role
|
|
|
|
|
node*: NodeProcess
|
2025-01-21 21:54:46 +01:00
|
|
|
|
2023-09-13 16:17:56 +02:00
|
|
|
Role* {.pure.} = enum
|
|
|
|
|
Client
|
2025-01-21 21:54:46 +01:00
|
|
|
|
2024-03-12 10:57:13 +01:00
|
|
|
MultiNodeSuiteError = object of CatchableError
|
2026-01-16 21:47:59 +11:00
|
|
|
SuiteTimeoutError = object of MultiNodeSuiteError
|
|
|
|
|
|
|
|
|
|
const HardhatPort {.intdefine.}: int = 8545
|
|
|
|
|
const CodexApiPort {.intdefine.}: int = 8080
|
|
|
|
|
const CodexDiscPort {.intdefine.}: int = 8090
|
|
|
|
|
const TestId {.strdefine.}: string = "TestId"
|
|
|
|
|
const CodexLogToFile {.booldefine.}: bool = false
|
|
|
|
|
const CodexLogLevel {.strdefine.}: string = ""
|
|
|
|
|
const CodexLogsDir {.strdefine.}: string = ""
|
|
|
|
|
|
|
|
|
|
proc raiseMultiNodeSuiteError(
|
|
|
|
|
msg: string, parent: ref CatchableError = nil
|
|
|
|
|
) {.raises: [MultiNodeSuiteError].} =
|
|
|
|
|
raise newException(MultiNodeSuiteError, msg, parent)
|
|
|
|
|
|
|
|
|
|
template withLock(lock: AsyncLock, body: untyped) =
|
|
|
|
|
if lock.isNil:
|
|
|
|
|
lock = newAsyncLock()
|
|
|
|
|
|
|
|
|
|
await lock.acquire()
|
|
|
|
|
try:
|
|
|
|
|
body
|
|
|
|
|
finally:
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
try:
|
2026-01-16 21:47:59 +11:00
|
|
|
lock.release()
|
|
|
|
|
except AsyncLockError as parent:
|
|
|
|
|
raiseMultiNodeSuiteError "lock error", parent
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
|
2025-03-24 16:47:05 +01:00
|
|
|
proc sanitize(pathSegment: string): string =
|
|
|
|
|
var sanitized = pathSegment
|
|
|
|
|
for invalid in invalidFilenameChars.items:
|
|
|
|
|
sanitized = sanitized.replace(invalid, '_').replace(' ', '_')
|
|
|
|
|
sanitized
|
|
|
|
|
|
|
|
|
|
proc getTempDirName*(starttime: string, role: Role, roleIdx: int): string =
|
2025-12-18 18:23:09 +01:00
|
|
|
getTempDir() / "Storage" / sanitize($starttime) / sanitize($role & "_" & $roleIdx)
|
2025-03-24 16:47:05 +01:00
|
|
|
|
2026-01-16 21:47:59 +11:00
|
|
|
template multinodesuite*(suiteName: string, body: untyped) =
|
|
|
|
|
asyncchecksuite suiteName:
|
2024-12-14 06:07:55 +01:00
|
|
|
var running {.inject, used.}: seq[RunningNode]
|
2024-12-18 15:10:36 +07:00
|
|
|
var bootstrapNodes: seq[string]
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
let starttime = now().format("yyyy-MM-dd'_'HH:mm:ss")
|
|
|
|
|
var currentTestName = ""
|
|
|
|
|
var nodeConfigs: NodeConfigs
|
|
|
|
|
var snapshot: JsonNode
|
2026-01-16 21:47:59 +11:00
|
|
|
var lastUsedHardhatPort = HardhatPort
|
|
|
|
|
var lastUsedCodexApiPort = CodexApiPort
|
|
|
|
|
var lastUsedCodexDiscPort = CodexDiscPort
|
|
|
|
|
var codexPortLock: AsyncLock
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
|
|
|
|
|
template test(tname, startNodeConfigs, tbody) =
|
|
|
|
|
currentTestName = tname
|
|
|
|
|
nodeConfigs = startNodeConfigs
|
|
|
|
|
test tname:
|
|
|
|
|
tbody
|
|
|
|
|
|
2026-01-16 21:47:59 +11:00
|
|
|
proc updatePort(url: var string, port: int) =
|
|
|
|
|
let parts = url.split(':')
|
|
|
|
|
url = @[parts[0], parts[1], $port].join(":")
|
2023-06-22 20:32:18 +10:00
|
|
|
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
proc newCodexProcess(
|
2024-03-12 10:57:13 +01:00
|
|
|
roleIdx: int, conf: CodexConfig, role: Role
|
2026-01-16 21:47:59 +11:00
|
|
|
): Future[NodeProcess] {.async: (raises: [MultiNodeSuiteError, CancelledError]).} =
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
let nodeIdx = running.len
|
2024-03-12 10:57:13 +01:00
|
|
|
var config = conf
|
2026-01-16 21:47:59 +11:00
|
|
|
let datadir = getDataDir(TestId, currentTestName, $starttime, $role, some roleIdx)
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
|
2024-03-12 10:57:13 +01:00
|
|
|
try:
|
2026-01-16 21:47:59 +11:00
|
|
|
if config.logFile.isSome or CodexLogToFile:
|
|
|
|
|
try:
|
|
|
|
|
let updatedLogFile = getLogFile(
|
|
|
|
|
CodexLogsDir, starttime, suiteName, currentTestName, $role, some roleIdx
|
|
|
|
|
)
|
|
|
|
|
config.withLogFile(updatedLogFile)
|
|
|
|
|
except IOError as e:
|
|
|
|
|
raiseMultiNodeSuiteError(
|
|
|
|
|
"failed to start " & $role &
|
|
|
|
|
" because logfile path could not be obtained: " & e.msg,
|
|
|
|
|
e,
|
|
|
|
|
)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
raiseMultiNodeSuiteError(
|
|
|
|
|
"failed to start " & $role &
|
|
|
|
|
" because logfile path could not be obtained: " & e.msg,
|
|
|
|
|
e,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
when CodexLogLevel != "":
|
|
|
|
|
config.addCliOption("--log-level", CodexLogLevel)
|
|
|
|
|
|
|
|
|
|
var apiPort, discPort: int
|
|
|
|
|
withLock(codexPortLock):
|
|
|
|
|
apiPort = await nextFreePort(lastUsedCodexApiPort + nodeIdx)
|
|
|
|
|
discPort = await nextFreePort(lastUsedCodexDiscPort + nodeIdx)
|
|
|
|
|
config.addCliOption("--api-port", $apiPort)
|
|
|
|
|
config.addCliOption("--disc-port", $discPort)
|
|
|
|
|
lastUsedCodexApiPort = apiPort
|
|
|
|
|
lastUsedCodexDiscPort = discPort
|
2024-03-12 10:57:13 +01:00
|
|
|
|
2024-12-18 15:10:36 +07:00
|
|
|
for bootstrapNode in bootstrapNodes:
|
|
|
|
|
config.addCliOption("--bootstrap-node", bootstrapNode)
|
2026-01-16 21:47:59 +11:00
|
|
|
|
2024-03-12 10:57:13 +01:00
|
|
|
config.addCliOption("--data-dir", datadir)
|
2025-01-09 23:41:22 +05:30
|
|
|
config.addCliOption("--nat", "none")
|
2024-03-12 10:57:13 +01:00
|
|
|
config.addCliOption("--listen-addrs", "/ip4/127.0.0.1/tcp/0")
|
|
|
|
|
except CodexConfigError as e:
|
|
|
|
|
raiseMultiNodeSuiteError "invalid cli option, error: " & e.msg
|
|
|
|
|
|
|
|
|
|
try:
|
2026-01-16 21:47:59 +11:00
|
|
|
let node = await CodexProcess.startNode(
|
|
|
|
|
config.cliArgs, config.debugEnabled, $role & $roleIdx
|
|
|
|
|
)
|
2024-03-12 10:57:13 +01:00
|
|
|
await node.waitUntilStarted()
|
|
|
|
|
trace "node started", nodeName = $role & $roleIdx
|
2026-01-16 21:47:59 +11:00
|
|
|
return node
|
|
|
|
|
except CodexConfigError as e:
|
|
|
|
|
raiseMultiNodeSuiteError "failed to get cli args from config: " & e.msg, e
|
2024-03-12 10:57:13 +01:00
|
|
|
except NodeProcessError as e:
|
2026-01-16 21:47:59 +11:00
|
|
|
raiseMultiNodeSuiteError "node not started, error: " & e.msg, e
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
|
|
|
|
|
proc clients(): seq[CodexProcess] {.used.} =
|
|
|
|
|
return collect:
|
|
|
|
|
for r in running:
|
|
|
|
|
if r.role == Role.Client:
|
|
|
|
|
CodexProcess(r.node)
|
|
|
|
|
|
2024-03-12 10:57:13 +01:00
|
|
|
proc startClientNode(conf: CodexConfig): Future[NodeProcess] {.async.} =
|
refactor: multinode integration test refactor (#662)
* refactor multi node test suite
Refactor the multinode test suite into the marketplace test suite.
- Arbitrary number of nodes can be started with each test: clients, providers, validators
- Hardhat can also be started locally with each test, usually for the purpose of saving and inspecting its log file.
- Log files for all nodes can be persisted on disk, with configuration at the test-level
- Log files, if persisted (as specified in the test), will be persisted to a CI artifact
- Node config is specified at the test-level instead of the suite-level
- Node/Hardhat process starting/stopping is now async, and runs much faster
- Per-node config includes:
- simulating proof failures
- logging to file
- log level
- log topics
- storage quota
- debug (print logs to stdout)
- Tests find next available ports when starting nodes, as closing ports on Windows can lag
- Hardhat is no longer required to be running prior to starting the integration tests (as long as Hardhat is configured to run in the tests).
- If Hardhat is already running, a snapshot will be taken and reverted before and after each test, respectively.
- If Hardhat is not already running and configured to run at the test-level, a Hardhat process will be spawned and torn down before and after each test, respectively.
* additional logging for debug purposes
* address PR feedback
- fix spelling
- revert change from catching ProviderError to SignerError -- this should be handled more consistently in the Market abstraction, and will be handled in another PR.
- remove method label from raiseAssert
- remove unused import
* Use API instead of command exec to test for free port
Use chronos `createStreamServer` API to test for free port by binding localhost address and port. Use `ServerFlags.ReuseAddr` to enable reuse of same IP/Port on multiple test runs.
* clean up
* remove upraises annotations from tests
* Update tests to work with updated erasure coding slot sizes
* update dataset size, nodes, tolerance to match valid ec params
Integration tests now have valid dataset sizes (blocks), tolerances, and number of nodes, to work with valid ec params. These values are validated when requested storage.
Print the rest api failure message (via doAssert) when a rest api call fails (eg the rest api may validate some ec params).
All integration tests pass when the async `clock.now` changes are reverted.
* dont use async clock for now
* fix workflow
* move integration logs uplod to reusable
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2024-02-19 15:55:39 +11:00
|
|
|
let clientIdx = clients().len
|
2026-01-17 06:03:54 +11:00
|
|
|
return await newCodexProcess(clientIdx, conf, Role.Client)
|
2023-06-22 20:32:18 +10:00
|
|
|
|
2026-01-17 06:03:54 +11:00
|
|
|
proc teardownImpl() {.async.} =
|
|
|
|
|
for nodes in @[clients()]:
|
2024-03-12 10:57:13 +01:00
|
|
|
for node in nodes:
|
|
|
|
|
await node.stop() # also stops rest client
|
2026-01-16 21:47:59 +11:00
|
|
|
try:
|
|
|
|
|
node.removeDataDir()
|
|
|
|
|
except CodexProcessError as e:
|
|
|
|
|
error "Failed to remove data dir during teardown", error = e.msg
|
2024-03-12 10:57:13 +01:00
|
|
|
|
|
|
|
|
running = @[]
|
|
|
|
|
|
|
|
|
|
template failAndTeardownOnError(message: string, tryBody: untyped) =
|
|
|
|
|
try:
|
|
|
|
|
tryBody
|
2026-01-16 21:47:59 +11:00
|
|
|
except CancelledError as e:
|
|
|
|
|
await teardownImpl()
|
|
|
|
|
when declared(teardownAllIMPL):
|
|
|
|
|
teardownAllIMPL()
|
|
|
|
|
fail()
|
|
|
|
|
quit(1)
|
2024-03-12 10:57:13 +01:00
|
|
|
except CatchableError as er:
|
|
|
|
|
fatal message, error = er.msg
|
|
|
|
|
echo "[FATAL] ", message, ": ", er.msg
|
|
|
|
|
await teardownImpl()
|
|
|
|
|
when declared(teardownAllIMPL):
|
|
|
|
|
teardownAllIMPL()
|
|
|
|
|
fail()
|
|
|
|
|
quit(1)
|
|
|
|
|
|
2025-03-17 17:08:24 -03:00
|
|
|
proc updateBootstrapNodes(
|
|
|
|
|
node: CodexProcess
|
2026-01-16 21:47:59 +11:00
|
|
|
): Future[void] {.async: (raises: [MultiNodeSuiteError]).} =
|
|
|
|
|
try:
|
|
|
|
|
without ninfo =? await node.client.info():
|
|
|
|
|
# raise CatchableError instead of Defect (with .get or !) so we
|
|
|
|
|
# can gracefully shutdown and prevent zombies
|
|
|
|
|
raiseMultiNodeSuiteError "Failed to get node info"
|
|
|
|
|
bootstrapNodes.add ninfo["spr"].getStr()
|
|
|
|
|
except CatchableError as e:
|
|
|
|
|
raiseMultiNodeSuiteError "Failed to get node info: " & e.msg, e
|
|
|
|
|
|
|
|
|
|
setupAll:
|
|
|
|
|
# When this file is run with `-d:chronicles_sinks=textlines[file]`, we
|
|
|
|
|
# need to set the log file path at runtime, otherwise chronicles didn't seem to
|
|
|
|
|
# create a log file even when using an absolute path
|
|
|
|
|
when defaultChroniclesStream.outputs is (FileOutput,) and CodexLogsDir.len > 0:
|
|
|
|
|
let logFile =
|
|
|
|
|
CodexLogsDir / sanitize(getAppFilename().extractFilename & ".chronicles.log")
|
|
|
|
|
let success = defaultChroniclesStream.outputs[0].open(logFile, fmAppend)
|
|
|
|
|
doAssert success, "Failed to open log file: " & logFile
|
2024-12-18 15:10:36 +07:00
|
|
|
|
2023-06-22 20:32:18 +10:00
|
|
|
setup:
|
2026-01-16 21:47:59 +11:00
|
|
|
trace "Setting up test", suite = suiteName, test = currentTestName, nodeConfigs
|
2024-03-12 10:57:13 +01:00
|
|
|
if var clients =? nodeConfigs.clients:
|
|
|
|
|
failAndTeardownOnError "failed to start client nodes":
|
|
|
|
|
for config in clients.configs:
|
|
|
|
|
let node = await startClientNode(config)
|
|
|
|
|
running.add RunningNode(role: Role.Client, node: node)
|
2025-03-17 17:08:24 -03:00
|
|
|
await CodexProcess(node).updateBootstrapNodes()
|
2024-03-12 10:57:13 +01:00
|
|
|
|
2023-06-22 20:32:18 +10:00
|
|
|
teardown:
|
2024-03-12 10:57:13 +01:00
|
|
|
await teardownImpl()
|
2026-01-16 21:47:59 +11:00
|
|
|
trace "Test completed", suite = suiteName, test = currentTestName
|
2023-06-22 20:32:18 +10:00
|
|
|
|
|
|
|
|
body
|