From 3cec32855dfe150cb3695370601a0c35e12de5a3 Mon Sep 17 00:00:00 2001 From: Mohammad Kermani Date: Mon, 6 May 2024 09:55:09 +0000 Subject: [PATCH] test: add scaling-pubsub test package --- .../workflows/scaling-test-docker-release.yml | 2 +- package-lock.json | 24 + tests/scaling-pubsub/.eslintignore | 1 + tests/scaling-pubsub/.terraform.lock.hcl | 24 + tests/scaling-pubsub/README.md | 23 + tests/scaling-pubsub/main.tf | 489 ++++++++++++++++++ tests/scaling-pubsub/package.json | 35 ++ tests/scaling-pubsub/src/node/Dockerfile | 18 + tests/scaling-pubsub/src/node/node.ts | 35 ++ tests/scaling-pubsub/src/relay/Dockerfile | 18 + tests/scaling-pubsub/src/relay/relay.ts | 14 + tests/scaling-pubsub/ts-node-esm-loader.js | 15 + tests/scaling-pubsub/tsconfig.json | 19 + tests/scaling-pubsub/variables.tf | 11 + 14 files changed, 727 insertions(+), 1 deletion(-) create mode 100644 tests/scaling-pubsub/.eslintignore create mode 100644 tests/scaling-pubsub/.terraform.lock.hcl create mode 100644 tests/scaling-pubsub/README.md create mode 100644 tests/scaling-pubsub/main.tf create mode 100644 tests/scaling-pubsub/package.json create mode 100644 tests/scaling-pubsub/src/node/Dockerfile create mode 100644 tests/scaling-pubsub/src/node/node.ts create mode 100644 tests/scaling-pubsub/src/relay/Dockerfile create mode 100644 tests/scaling-pubsub/src/relay/relay.ts create mode 100644 tests/scaling-pubsub/ts-node-esm-loader.js create mode 100644 tests/scaling-pubsub/tsconfig.json create mode 100644 tests/scaling-pubsub/variables.tf diff --git a/.github/workflows/scaling-test-docker-release.yml b/.github/workflows/scaling-test-docker-release.yml index 9109f88..3107f91 100644 --- a/.github/workflows/scaling-test-docker-release.yml +++ b/.github/workflows/scaling-test-docker-release.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: role: [node, relay] - test-name: ['', peer-discovery] + test-name: ['', peer-discovery, pubsub] name: Build and Push Scaling Test Docker Image permissions: write-all diff --git a/package-lock.json b/package-lock.json index 8a11963..9b95ecf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2548,6 +2548,10 @@ "resolved": "tests/scaling-peer-discovery", "link": true }, + "node_modules/@rosenet-tests/scaling-pubsub": { + "resolved": "tests/scaling-pubsub", + "link": true + }, "node_modules/@rosenet-tests/simple-star": { "resolved": "tests/simple-star", "link": true @@ -10055,6 +10059,26 @@ "typescript": "^5.3.3" } }, + "tests/scaling-pubsub": { + "version": "0.0.0", + "license": "GPL-3.0", + "dependencies": { + "@rosen-bridge/rosenet-node": "^0.0.0", + "@rosen-bridge/rosenet-relay": "^0.0.0" + }, + "devDependencies": { + "@types/node": "^20.11.9", + "@typescript-eslint/eslint-plugin": "^6.19.1", + "@typescript-eslint/parser": "^6.19.1", + "eslint": "^8.56.0", + "eslint-config-prettier": "^9.1.0", + "extensionless": "^1.9.6", + "prettier": "^3.2.4", + "ts-node": "^10.7.0", + "tsconfig-paths": "^4.1.2", + "typescript": "^5.3.3" + } + }, "tests/simple-star": { "name": "@rosenet-tests/simple-star", "version": "0.0.0", diff --git a/tests/scaling-pubsub/.eslintignore b/tests/scaling-pubsub/.eslintignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/tests/scaling-pubsub/.eslintignore @@ -0,0 +1 @@ +dist diff --git a/tests/scaling-pubsub/.terraform.lock.hcl b/tests/scaling-pubsub/.terraform.lock.hcl new file mode 100644 index 0000000..f526901 --- /dev/null +++ b/tests/scaling-pubsub/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "tofu init". +# Manual edits may be lost in future updates. + +provider "registry.opentofu.org/kreuzwerker/docker" { + version = "3.0.2" + constraints = "~> 3.0.1" + hashes = [ + "h1:cT2ccWOtlfKYBUE60/v2/4Q6Stk1KYTNnhxSck+VPlU=", + "zh:15b0a2b2b563d8d40f62f83057d91acb02cd0096f207488d8b4298a59203d64f", + "zh:23d919de139f7cd5ebfd2ff1b94e6d9913f0977fcfc2ca02e1573be53e269f95", + "zh:38081b3fe317c7e9555b2aaad325ad3fa516a886d2dfa8605ae6a809c1072138", + "zh:4a9c5065b178082f79ad8160243369c185214d874ff5048556d48d3edd03c4da", + "zh:5438ef6afe057945f28bce43d76c4401254073de01a774760169ac1058830ac2", + "zh:60b7fadc287166e5c9873dfe53a7976d98244979e0ab66428ea0dea1ebf33e06", + "zh:61c5ec1cb94e4c4a4fb1e4a24576d5f39a955f09afb17dab982de62b70a9bdd1", + "zh:a38fe9016ace5f911ab00c88e64b156ebbbbfb72a51a44da3c13d442cd214710", + "zh:c2c4d2b1fd9ebb291c57f524b3bf9d0994ff3e815c0cd9c9bcb87166dc687005", + "zh:d567bb8ce483ab2cf0602e07eae57027a1a53994aba470fa76095912a505533d", + "zh:e83bf05ab6a19dd8c43547ce9a8a511f8c331a124d11ac64687c764ab9d5a792", + "zh:e90c934b5cd65516fbcc454c89a150bfa726e7cf1fe749790c7480bbeb19d387", + "zh:f05f167d2eaf913045d8e7b88c13757e3cf595dd5cd333057fdafc7c4b7fed62", + "zh:fcc9c1cea5ce85e8bcb593862e699a881bd36dffd29e2e367f82d15368659c3d", + ] +} diff --git a/tests/scaling-pubsub/README.md b/tests/scaling-pubsub/README.md new file mode 100644 index 0000000..b41d364 --- /dev/null +++ b/tests/scaling-pubsub/README.md @@ -0,0 +1,23 @@ +# RoseNet scaling pubsub test + +## Table of contents + +- [Introduction](#introduction) +- [Usage](#usage) + +## Introduction + +RoseNet scaling pubsub test + +## Usage + +You need to have [OpenTofu](https://opentofu.org/) installed. Then, after +[passing required variables](https://opentofu.org/docs/language/values/variables/#assigning-values-to-root-module-variables) (defined in [`variables.tf`](./variables.tf)), +run the following commands. It should complete with no errors. + +```bash +tofu init +tofu apply +``` + +Finally run `tofu destroy` to destroy the infrastructure. diff --git a/tests/scaling-pubsub/main.tf b/tests/scaling-pubsub/main.tf new file mode 100644 index 0000000..fd35ecc --- /dev/null +++ b/tests/scaling-pubsub/main.tf @@ -0,0 +1,489 @@ +terraform { + required_providers { + docker = { + source = "kreuzwerker/docker" + version = "~> 3.0.1" + } + } +} + +provider "docker" { + alias = "machine-0" + host = var.machines[0] +} + +provider "docker" { + alias = "machine-1" + host = var.machines[1] +} + +provider "docker" { + alias = "machine-2" + host = var.machines[2] +} + +provider "docker" { + alias = "machine-3" + host = var.machines[3] +} + +provider "docker" { + alias = "machine-4" + host = var.machines[4] +} + +provider "docker" { + alias = "machine-5" + host = var.machines[5] +} + +provider "docker" { + alias = "machine-6" + host = var.machines[6] +} + +provider "docker" { + alias = "machine-7" + host = var.machines[7] +} + +provider "docker" { + alias = "machine-8" + host = var.machines[8] +} + +provider "docker" { + alias = "machine-9" + host = var.machines[9] +} + +provider "docker" { + alias = "relay-machine" + host = var.relay-host +} + +locals { + relay_peer_id = "16Uiu2HAmLhLvBoYaoZfaMUKuibM6ac163GwKY74c5kiSLg5KvLpY" + relay_private_key = "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED8FB" + node_peer_ids = [ + "16Uiu2HAkykduGyaTTrv2sbS5VPiM1opuB8nwrLAFFbkcKJo12Rfp", + "16Uiu2HAm3BY2vHeracYytkbcr4uZN3uXq8RfaQtFQoTvbNUrBb2f", + "16Uiu2HAm2WNNuTmHNiVK2hYhJu7ZBWmKj7mHNG1aiX5WaXMrZG9n", + "16Uiu2HAmNTC7kpXQbovW1kEtCJ5CDEtAGw2DcZ22SBBvGJS18M7E", + "16Uiu2HAmTH1Rya56bKc84B8YbXFCrjpTra6ApHA92FPRTzkWHVjt", + "16Uiu2HAmQYggzsuCnePKhHMJfRJsZAAauFcrpkZGYuiXfkqueQTy", + "16Uiu2HAm4hsxuSJJHHBKfN1xXSauR1gwWLmvQCVjRkYDAzEvArWr", + "16Uiu2HAmNox2uEXiBhNFDN6ssHMe4b9eBffodaTSQeZzs25sspVY", + "16Uiu2HAmVhSVkyzwZvcHUyY7J7pU5PDFJ4iVC5hHb3A2Hs3uogKn", + "16Uiu2HAm8zG2vtPf2Q4ExhsSZtcCTzTzCxY4F64Vtduc6kHPEdNQ", + "16Uiu2HAmSjon8qun6SANsLP9Rm2SrX1Zmwb3XwVinF1UYH6gobUi", + "16Uiu2HAm4yUHDkxyoXVQpUanR8cLfzXMdSBXNHaBTMvzBKiqkJSD", + "16Uiu2HAmULwMmGM8r9WnAfwcyUQKW5kk7QyG7omihCZLQaxHL3id", + "16Uiu2HAmTXHmJEc6eMNXswSA2zGEjC6mQLimFE4xUHc2vBbbiaie", + "16Uiu2HAkztUutiTKFrjnpy8Bsxxwt8WcUQGJN3wrp562GMokTpfs", + "16Uiu2HAkwA4gJ9191vMaowQb9uRFrJsFKdKvwHkusXARkfZD2m4m", + "16Uiu2HAkvK2ZZSczh3gM7UKLKUtzNywnKz6ZyRpHvarDZCVCdwuu", + "16Uiu2HAmDGo4odJjeNqkA3U5QaNcgAkTiGNxg1n7N5vhe4GihcTD", + "16Uiu2HAmKXAFrEZbhDaF6w6dDbW4brhoQidLjUvovBo78pVEbQ1w", + "16Uiu2HAm6BkEADAtEN6YdWwxTJo2FpTmZ9VoswwpEjX1uPs9sW1V", + "16Uiu2HAmD2xpc8sgQC6j42Tz4SWmkVXAcwMJnfXHXmDAcfNDqhVL", + "16Uiu2HAmRL4FvuU6p3QgYQXPZyE6KBPTGiUjJmJjcoKFQpPu8FRs", + "16Uiu2HAm2P3EDniN91qv8mxyTxvtqLR5sgwL3tbyMnTCfhxe9Qhx", + "16Uiu2HAmRr7fccFXHqD6VGXJTcyuwVNjEp1dwk66Updf8YWtA3Tw", + "16Uiu2HAkxcr6mjnQUePe7axVpjQEjuUNB43bxrKdfaNVJe43FxeQ", + "16Uiu2HAmUiv8fF9BTmTzWeWKm8kpge7PHq4cKrgjgdZ2w6WpxHX9", + "16Uiu2HAmRWK6Q2cdvDfaaMg5Ybt1BctxTp5AB16CpPH61PsGKS74", + "16Uiu2HAmMJPD8Yr6aXHCrtUF91p7ifXhhvrsJdRjr4vr4LfXYwki", + "16Uiu2HAmGtoHooFuHddu44rtm5yoodpyfP6hzTBeo7JPAYuwwAam", + "16Uiu2HAm1vQzkH3rUaHPTHWX74fZoyT1URNDqHNCaSqLwoDSVppR", + "16Uiu2HAkzNB4nkwnBPy5GPRmdDFJTEBXRUAArAUDaYpNCYDrLTrB", + "16Uiu2HAm3nnNwidpojv9e8FjMMrk2C1wxXD82WaW51gFJMw3Pqf9", + "16Uiu2HAmPrKEPdS4WDSPTxVAX4J1XpKaKcyWUtcgQ7eq17AnLiEf", + "16Uiu2HAmPUJShifRseVUX7Ed3HBTBrn3uB2EX8bfaDQoRKWfgYpH", + "16Uiu2HAmE2opd1R4Aw31EWrPGvjpMTdBejU9H59RwDiSJHGwaq41", + "16Uiu2HAkv5pTUJHN5T9YZEXr3M5CnnsMPt2VxTqFg2Jdc1PZnu5L", + "16Uiu2HAmJpY3D531m9dy6XHZA93Mx5JRpLFAHWoKNcwybZSHYedw", + "16Uiu2HAmPVLymKwe8Tn563P8Zm2ypNQzMebz4VHL5M6WcRpejHFK", + "16Uiu2HAkz9qxRtMwbEEctXvx7U7i9i5eHpk6qzDgYTtMoLibJ14j", + "16Uiu2HAmRUtGay745Rmc4EUxxykVtadgKvgYPbf9mj4JmrWJtThp", + ] + node_private_keys = [ + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED800", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED801", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED802", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED803", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED804", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED805", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED806", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED807", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED808", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED809", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED810", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED811", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED812", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED813", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED814", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED815", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED816", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED817", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED818", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED819", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED820", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED821", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED822", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED823", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED824", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED825", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED826", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED827", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED828", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED829", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED830", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED831", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED832", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED833", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED834", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED835", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED836", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED837", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED838", + "0802122053DADF1D5A164D6B4ACDB15E24AA4C5B1D3461BDBD42ABEDB0A4404D56CED839", + ] +} + +data "docker_registry_image" "rosenet-node" { + name = "ghcr.io/rosen-bridge/scaling-pubsub-test-node" +} + +data "docker_registry_image" "rosenet-relay" { + name = "ghcr.io/rosen-bridge/scaling-pubsub-test-relay" +} + +resource "docker_image" "rosenet-node-0" { + provider = docker.machine-0 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-1" { + provider = docker.machine-1 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-2" { + provider = docker.machine-2 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-3" { + provider = docker.machine-3 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-4" { + provider = docker.machine-4 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-5" { + provider = docker.machine-5 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-6" { + provider = docker.machine-6 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-7" { + provider = docker.machine-7 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-8" { + provider = docker.machine-8 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-node-9" { + provider = docker.machine-9 + + name = data.docker_registry_image.rosenet-node.name + pull_triggers = [data.docker_registry_image.rosenet-node.sha256_digest] +} + +resource "docker_image" "rosenet-relay" { + provider = docker.relay-machine + + name = data.docker_registry_image.rosenet-relay.name + pull_triggers = [data.docker_registry_image.rosenet-relay.sha256_digest] +} + +resource "docker_container" "rosenet-node-0" { + provider = docker.machine-0 + count = 4 + + name = "node-${count.index}" + image = docker_image.rosenet-node-0.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-1" { + provider = docker.machine-1 + count = 4 + + name = "node-${count.index + 4}" + image = docker_image.rosenet-node-1.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 4]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 4]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-2" { + provider = docker.machine-2 + count = 4 + + name = "node-${count.index + 8}" + image = docker_image.rosenet-node-2.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 8]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 8]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-3" { + provider = docker.machine-3 + count = 4 + + name = "node-${count.index + 12}" + image = docker_image.rosenet-node-3.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 12]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 12]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-4" { + provider = docker.machine-4 + count = 4 + + name = "node-${count.index + 16}" + image = docker_image.rosenet-node-4.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 16]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 16]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-5" { + provider = docker.machine-5 + count = 4 + + name = "node-${count.index + 20}" + image = docker_image.rosenet-node-5.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 20]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 20]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-6" { + provider = docker.machine-6 + count = 4 + + name = "node-${count.index + 24}" + image = docker_image.rosenet-node-6.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 24]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 24]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-7" { + provider = docker.machine-7 + count = 4 + + name = "node-${count.index + 28}" + image = docker_image.rosenet-node-7.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 28]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 28]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-8" { + provider = docker.machine-8 + count = 4 + + name = "node-${count.index + 32}" + image = docker_image.rosenet-node-8.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 32]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 32]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-node-9" { + provider = docker.machine-9 + count = 4 + + name = "node-${count.index + 36}" + image = docker_image.rosenet-node-9.image_id + env = [ + "RELAY_MULTIADDR=/ip4/${var.relay-ip}/tcp/33333/p2p/${local.relay_peer_id}", "PRIVATE_KEY=${local.node_private_keys[count.index + 36]}", "ALL_PEER_IDS=${join("," ,local.node_peer_ids)}", "NODE_PEER_ID=${local.node_peer_ids[count.index + 36]}"] + + depends_on = [ + docker_container.rosenet-relay, + docker_image.rosenet-node-0, + docker_image.rosenet-node-1, + docker_image.rosenet-node-2, + docker_image.rosenet-node-3, + docker_image.rosenet-node-4, + docker_image.rosenet-node-5, + docker_image.rosenet-node-6, + docker_image.rosenet-node-7, + docker_image.rosenet-node-8, + docker_image.rosenet-node-9, + ] +} + +resource "docker_container" "rosenet-relay" { + provider = docker.relay-machine + + name = "relay" + image = docker_image.rosenet-relay.image_id + env = ["PRIVATE_KEY=${local.relay_private_key}", "WHITELIST=${join(",", local.node_peer_ids)}", "LISTEN_PORT=33333"] + ports { + internal = 33333 + external = 33333 + } +} diff --git a/tests/scaling-pubsub/package.json b/tests/scaling-pubsub/package.json new file mode 100644 index 0000000..fefbacd --- /dev/null +++ b/tests/scaling-pubsub/package.json @@ -0,0 +1,35 @@ +{ + "name": "@rosenet-tests/scaling-pubsub", + "private": true, + "version": "0.0.0", + "description": "RoseNet scaling pubsub test", + "repository": "https://github.com/rosen-bridge/rosenet", + "license": "GPL-3.0", + "author": "Rosen Team", + "type": "module", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "lint": "eslint --fix . && npm run prettify", + "prettify": "prettier --write . --ignore-path ./.gitignore", + "start:node": "node --loader ./ts-node-esm-loader.js --loader extensionless ./src/node/node.ts", + "start:relay": "node --loader ./ts-node-esm-loader.js --loader extensionless ./src/relay/relay.ts", + "type-check": "tsc --noEmit" + }, + "devDependencies": { + "@types/node": "^20.11.9", + "@typescript-eslint/eslint-plugin": "^6.19.1", + "@typescript-eslint/parser": "^6.19.1", + "eslint": "^8.56.0", + "eslint-config-prettier": "^9.1.0", + "extensionless": "^1.9.6", + "prettier": "^3.2.4", + "ts-node": "^10.7.0", + "tsconfig-paths": "^4.1.2", + "typescript": "^5.3.3" + }, + "dependencies": { + "@rosen-bridge/rosenet-node": "^0.0.0", + "@rosen-bridge/rosenet-relay": "^0.0.0" + } +} diff --git a/tests/scaling-pubsub/src/node/Dockerfile b/tests/scaling-pubsub/src/node/Dockerfile new file mode 100644 index 0000000..993dee0 --- /dev/null +++ b/tests/scaling-pubsub/src/node/Dockerfile @@ -0,0 +1,18 @@ +FROM node:20.11 + +WORKDIR /app + +COPY package.json . +COPY package-lock.json . +COPY packages/rosenet-node/package.json ./packages/rosenet-node/ +COPY packages/rosenet-relay/package.json ./packages/rosenet-relay/ +COPY packages/utils/package.json ./packages/utils/ +COPY tests/scaling-pubsub/package.json ./tests/scaling-pubsub/ +RUN npm ci + +COPY . . +RUN npm run build + +WORKDIR /app/tests/scaling-pubsub + +CMD npm run start:node diff --git a/tests/scaling-pubsub/src/node/node.ts b/tests/scaling-pubsub/src/node/node.ts new file mode 100644 index 0000000..05863d8 --- /dev/null +++ b/tests/scaling-pubsub/src/node/node.ts @@ -0,0 +1,35 @@ +import { createRoseNetNode } from '@rosen-bridge/rosenet-node'; + +const node = await createRoseNetNode({ + logger: console, + relayMultiaddrs: [process.env.RELAY_MULTIADDR!], + privateKey: process.env.PRIVATE_KEY!, +}); + +await node.start(); + +const wait = () => + new Promise((resolve) => { + setTimeout(resolve, 1 + Math.random() * 4); + }); + +setTimeout(() => { + setInterval(async () => { + for (let i = 0; i < 10; i++) { + try { + node.publish('rosenet-news', Date.now().toString()); + } catch (error) { + console.warn( + `tried to publish a message but failed due to error: ${error}`, + ); + } + await wait(); + } + }, 10_000); +}, 30_000); + +node.subscribe('rosenet-news', (message) => { + console.info( + `Message received: ${message} (delay: ${(Date.now() - +message) / 1000}s)`, + ); +}); diff --git a/tests/scaling-pubsub/src/relay/Dockerfile b/tests/scaling-pubsub/src/relay/Dockerfile new file mode 100644 index 0000000..8b1a249 --- /dev/null +++ b/tests/scaling-pubsub/src/relay/Dockerfile @@ -0,0 +1,18 @@ +FROM node:20.11 + +WORKDIR /app + +COPY package.json . +COPY package-lock.json . +COPY packages/rosenet-node/package.json ./packages/rosenet-node/ +COPY packages/rosenet-relay/package.json ./packages/rosenet-relay/ +COPY packages/utils/package.json ./packages/utils/ +COPY tests/scaling-pubsub/package.json ./tests/scaling-pubsub/ +RUN npm ci + +COPY . . +RUN npm run build + +WORKDIR /app/tests/scaling-pubsub + +CMD npm run start:relay diff --git a/tests/scaling-pubsub/src/relay/relay.ts b/tests/scaling-pubsub/src/relay/relay.ts new file mode 100644 index 0000000..beb445a --- /dev/null +++ b/tests/scaling-pubsub/src/relay/relay.ts @@ -0,0 +1,14 @@ +import { createRoseNetRelay } from '@rosen-bridge/rosenet-relay'; + +const node = await createRoseNetRelay({ + logger: console, + privateKey: process.env.PRIVATE_KEY!, + listen: { + host: '0.0.0.0', + port: Number(process.env.LISTEN_PORT), + }, + whitelist: process.env.WHITELIST!.split(','), + maxReservations: 40, +}); + +node.start(); diff --git a/tests/scaling-pubsub/ts-node-esm-loader.js b/tests/scaling-pubsub/ts-node-esm-loader.js new file mode 100644 index 0000000..6a27e30 --- /dev/null +++ b/tests/scaling-pubsub/ts-node-esm-loader.js @@ -0,0 +1,15 @@ +import { resolve as resolveTs } from 'ts-node/esm'; +import * as tsConfigPaths from 'tsconfig-paths'; +import { pathToFileURL } from 'url'; + +const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig(); +const matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, paths); + +export function resolve(specifier, ctx, defaultResolve) { + const match = matchPath(specifier); + return match + ? resolveTs(pathToFileURL(`${match}`).href, ctx, defaultResolve) + : resolveTs(specifier, ctx, defaultResolve); +} + +export { load, transformSource } from 'ts-node/esm'; diff --git a/tests/scaling-pubsub/tsconfig.json b/tests/scaling-pubsub/tsconfig.json new file mode 100644 index 0000000..42af8ed --- /dev/null +++ b/tests/scaling-pubsub/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist", + "baseUrl": ".", + }, + "include": ["src"], + "ts-node": { + "esm": true, + }, + "references": [ + { + "path": "../../packages/rosenet-node/tsconfig.build.json", + }, + { + "path": "../../packages/rosenet-relay/tsconfig.build.json", + }, + ], +} diff --git a/tests/scaling-pubsub/variables.tf b/tests/scaling-pubsub/variables.tf new file mode 100644 index 0000000..6518b49 --- /dev/null +++ b/tests/scaling-pubsub/variables.tf @@ -0,0 +1,11 @@ +variable "machines" { + type = list(string) +} + +variable "relay-host" { + type = string +} + +variable "relay-ip" { + type = string +}