This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[zombinet] initial implementation of zombienet backchannel #4377
Merged
+430
−1
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f9ef6b9
initial impl zombienet backchannel
pepoviola ce50d2f
clean code
pepoviola 46c25b3
changes from feedback
pepoviola 6a3b7c6
fmt and typo
pepoviola e6f73a1
remove default comment
pepoviola b3be116
refactor to use ws tx/rx
pepoviola b3eed29
fmt
pepoviola 91b6975
Merge branch 'master' into javier-zombienet-backchannel
pepoviola 5953051
derive Clone for ZombienetBackchannel
pepoviola e340d32
Revert "derive Clone for ZombienetBackchannel"
pepoviola 0ccb705
change tracing prefix value
pepoviola 39dae39
Merge branch 'master' into javier-zombienet-backchannel
pepoviola f3014e7
refactor backchannel
pepoviola 1558d42
Update node/zombienet-backchannel/Cargo.toml
pepoviola bd729ae
add docs to broadcaster methods
pepoviola 486794f
add more docs
pepoviola ed47fee
Merge branch 'master' into javier-zombienet-backchannel
pepoviola 16a7b99
fmt
pepoviola c83269d
Merge branch 'master' into javier-zombienet-backchannel
pepoviola 1e001cd
fix spellcheck
pepoviola d1e4223
update lock file
pepoviola 1a38285
remove unused
pepoviola e4d9dbc
fmt
pepoviola c5a0791
Merge branch 'master' into javier-zombienet-backchannel
pepoviola 9cda227
changes from feedback
pepoviola d14b7c8
fmt
pepoviola 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
Next
Next commit
initial impl zombienet backchannel
- Loading branch information
commit f9ef6b978ebd0caaa2c62dbbbec149576be0ae1b
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [package] | ||
| name = "backchannel-cli" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [package] | ||
| name = "zombienet-backchannel" | ||
| description = "Zombienet backchannel to notify test runner and coordinate with malus actors." | ||
| license = "GPL-3.0-only" | ||
| version = "0.9.13" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
| edition = "2018" | ||
| readme = "README.md" | ||
| publish = false | ||
|
|
||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
pepoviola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [dependencies] | ||
| # futures-channel = "0.3" | ||
| tokio = { version = "1.0.0", default-features = false, features = ["macros", "net", "rt-multi-thread"] } | ||
| url = "2.0.0" | ||
| tokio-tungstenite = "0.16" | ||
| futures-util = "0.3.18" | ||
| parity-scale-codec = { version = "2.3.1", features = ["derive"] } | ||
| reqwest = "0.11" | ||
| thiserror = "1.0.30" | ||
| log = "0.4.13" | ||
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,57 @@ | ||
| /// Provides a backchannel to zombienet test runner. | ||
pepoviola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| use std::env; | ||
|
|
||
| use futures_util::{StreamExt, stream::SplitStream}; | ||
| use tokio::net::TcpStream; | ||
| use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async}; | ||
| use parity_scale_codec as scale_codec; | ||
pepoviola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| mod errors; | ||
| use errors::BackchannelError; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct ZombienetBackchannel { | ||
| pub inner: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>> | ||
| } | ||
|
|
||
| const BACKCHANNEL_HOST: &str = "backchannel"; | ||
| const BACKCHANNEL_PORT: &str = "3000"; | ||
|
|
||
| impl ZombienetBackchannel { | ||
| pub async fn connect() -> Result<ZombienetBackchannel,BackchannelError> { | ||
| let backchannel_host = env::var("BACKCHANNEL_HOST").unwrap_or_else(|_| BACKCHANNEL_HOST.to_string()); | ||
| let backchannel_port = env::var("BACKCHANNEL_PORT").unwrap_or_else(|_| BACKCHANNEL_PORT.to_string()); | ||
|
|
||
| let ws_url = format!("ws://{}:{}/ws", backchannel_host, backchannel_port); | ||
| log::debug!("Connecting to : {}",&ws_url); | ||
| let (ws_stream, _) = connect_async(ws_url).await.map_err(|_| BackchannelError::CantConnectToWS)?; | ||
| let (_write, read) = ws_stream.split(); | ||
|
|
||
| Ok( ZombienetBackchannel { | ||
pepoviola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| inner: read | ||
| }) | ||
| } | ||
|
|
||
| pub async fn send(key: &'static str, val: impl scale_codec::Encode) -> Result<(),BackchannelError> { | ||
| let backchannel_host = env::var("BACKCHANNEL_HOST").unwrap_or_else(|_| BACKCHANNEL_HOST.to_string()); | ||
| let backchannel_port = env::var("BACKCHANNEL_PORT").unwrap_or_else(|_| BACKCHANNEL_PORT.to_string()); | ||
|
|
||
| let client = reqwest::Client::new(); | ||
| let encoded = val.encode(); | ||
| let body = String::from_utf8_lossy(&encoded); | ||
| let zombienet_endpoint = format!("http://{}:{}/{}",backchannel_host, backchannel_port, key); | ||
|
|
||
| log::debug!("Sending to : {}",&zombienet_endpoint); | ||
pepoviola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let _res = client.post(zombienet_endpoint) | ||
| .body(body.to_string()) | ||
| .send() | ||
| .await.map_err(|e| { | ||
| log::error!("Error sending new item: {}",e); | ||
| BackchannelError::SendItemFail | ||
| })?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.