-
Notifications
You must be signed in to change notification settings - Fork 383
Crude attempt at finding open ports #346
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ab06d1
added example test for frontier (#343)
joelamouche 3f893f1
move staking test spec to node/chainspec (#335)
amarsinghcodes d306e78
Crude attempt at finding open ports
notlesh 9af4a89
npx -w
notlesh 5cf37a0
Add missing file
notlesh 1f80688
Adds random port and parallel test execution
b193e1f
Fixed ethers test
1614a49
Adds delay to node start in test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright 2019-2021 PureStake Inc. | ||
| // This file is part of Moonbeam. | ||
|
|
||
| // Moonbeam is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Moonbeam is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Embedded specs for testing purposes, must be compiled with --features=test-spec | ||
| use crate::chain_spec::{moonbeam_inflation_config, testnet_genesis, ChainSpec, Extensions}; | ||
| use cumulus_primitives_core::ParaId; | ||
| use moonbeam_runtime::{AccountId, GLMR}; | ||
| use sc_service::ChainType; | ||
| use std::str::FromStr; | ||
|
|
||
| /// Generate testing chain_spec for staking integration tests with accounts initialized for | ||
| /// collating and nominating. | ||
| pub fn staking_spec(para_id: ParaId) -> ChainSpec { | ||
| ChainSpec::from_genesis( | ||
| "Moonbase Development Testnet", | ||
| "staking", | ||
| ChainType::Local, | ||
| move || { | ||
| testnet_genesis( | ||
| // Root | ||
| AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b").unwrap(), | ||
| // Collators | ||
| vec![ | ||
| ( | ||
| AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b").unwrap(), | ||
| None, | ||
| 1_000 * GLMR, | ||
| ), | ||
| ( | ||
| AccountId::from_str("C0F0f4ab324C46e55D02D0033343B4Be8A55532d").unwrap(), | ||
| None, | ||
| 1_000 * GLMR, | ||
| ), | ||
| ], | ||
| // Inflation config | ||
| moonbeam_inflation_config(), | ||
| // Endowed accounts (each minted 1 << 80 balance) | ||
| vec![ | ||
| AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b").unwrap(), | ||
| AccountId::from_str("C0F0f4ab324C46e55D02D0033343B4Be8A55532d").unwrap(), | ||
| AccountId::from_str("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB").unwrap(), | ||
| AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(), | ||
| ], | ||
| para_id, | ||
| // Chain ID | ||
| 1280, | ||
| ) | ||
| }, | ||
| vec![], | ||
| None, | ||
| None, | ||
| Some(serde_json::from_str("{\"tokenDecimals\": 18}").expect("Provided valid json map")), | ||
| Extensions { | ||
| relay_chain: "local_testnet".into(), | ||
| para_id: para_id.into(), | ||
| }, | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { expect } from "chai"; | ||
|
|
||
| import { customRequest } from "../tests/util"; | ||
| import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY, TEST_ACCOUNT } from "../tests/constants"; | ||
| import { | ||
| createAndFinalizeBlockWithFrontier, | ||
| describeWithFrontier, | ||
| } from "../tests/util/testWithFrontier"; | ||
|
|
||
| const FRONTIER_GENESIS_ACCOUNT_BALANCE = "340282366920938463463374607431768211455"; | ||
|
|
||
| // This is an example of a Frontier test. It requires to have a clone of frontier in the same repo | ||
| // The binary needs to be built with `cargo build --no-default-features --features=manual-seal` | ||
| describeWithFrontier("Frontier RPC (Balance)", `frontier-specs.json`, (context) => { | ||
| it("genesis balance is setup correctly (web3)", async function () { | ||
| expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT)).to.equal( | ||
| FRONTIER_GENESIS_ACCOUNT_BALANCE | ||
| ); | ||
| }); | ||
| it("balance to be updated after transfer", async function () { | ||
| this.timeout(15000); | ||
|
|
||
| const tx = await context.web3.eth.accounts.signTransaction( | ||
| { | ||
| from: GENESIS_ACCOUNT, | ||
| to: TEST_ACCOUNT, | ||
| value: "0x200", // Must be higher than ExistentialDeposit (0) | ||
| gasPrice: "0x01", | ||
| gas: "0x100000", | ||
| }, | ||
| GENESIS_ACCOUNT_PRIVATE_KEY | ||
| ); | ||
| await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]); | ||
| await createAndFinalizeBlockWithFrontier(context.web3); | ||
| expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT)).to.equal( | ||
| "340282366920938463463374607431768189943" | ||
| ); | ||
| expect(await context.web3.eth.getBalance(TEST_ACCOUNT)).to.equal("512"); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import tcpPortUsed from "tcp-port-used"; | ||
|
|
||
| export async function findAvailablePorts() { | ||
| const availablePorts = await Promise.all( | ||
| [null, null, null].map(async (_, index) => { | ||
| let selectedPort = 0; | ||
| let port = 1024 + index * 20000 + (process.pid % 20000); | ||
| let endingPort = 65535; | ||
| while (!selectedPort && port < endingPort) { | ||
| const inUse = await tcpPortUsed.check(port, "127.0.0.1"); | ||
| if (!inUse) { | ||
| selectedPort = port; | ||
| } | ||
| port++; | ||
| } | ||
| if (!selectedPort) { | ||
| throw new Error(`No available port`); | ||
| } | ||
| return selectedPort; | ||
| }) | ||
| ); | ||
|
|
||
| return { | ||
| p2pPort: availablePorts[0], | ||
| rpcPort: availablePorts[1], | ||
| wsPort: availablePorts[2], | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would design it differently. The risk here comes from the fact it is checking the ports incrementally, starting from the same number each time, the race condition are more likely to happen in that case. It is also not efficient.
Using a random port might be more effective
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this is for the parallel mode, not the serial one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Turns out this isn't exactly a trivial problem... I'll leave this link here: mochajs/mocha#4456