From b2b80edcd1e445b4e62be0fa42bd2f00d7b4745a Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 28 Oct 2022 12:28:34 -0700 Subject: [PATCH] Enable CI for Windows (#603) --- .gitattributes | 1 + .github/workflows/ci.yaml | 8 ++++++- Cargo.lock | 50 +++++++++++++++------------------------ Cargo.toml | 1 - tests/command_builder.rs | 25 ++++---------------- tests/lib.rs | 2 -- tests/server.rs | 31 ++++++++++++++++-------- 7 files changed, 53 insertions(+), 65 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..fa1385d99a --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3e5ef5fe10..f84d01bb19 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,8 +17,9 @@ jobs: strategy: matrix: os: - - ubuntu-latest - macos-latest + - ubuntu-latest + - windows-latest runs-on: ${{matrix.os}} @@ -41,8 +42,13 @@ jobs: run: cargo update --locked --package ord - name: Test + if: ${{ matrix.os != 'windows-latest' }} run: cargo test --all + - name: Build Tests + if: ${{ matrix.os == 'windows-latest' }} + run: cargo build --tests + - name: Clippy run: cargo clippy --all --all-targets diff --git a/Cargo.lock b/Cargo.lock index 120039faa8..646f945240 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,16 +223,16 @@ dependencies = [ [[package]] name = "async-io" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e21f3a490c72b3b0cf44962180e60045de2925d8dff97918f7ee43c8f637c7" +checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" dependencies = [ + "async-lock", "autocfg", "concurrent-queue", "futures-lite", "libc", "log", - "once_cell", "parking", "polling", "slab", @@ -449,9 +449,9 @@ checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" [[package]] name = "bitcoin" -version = "0.29.1" +version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cb36de3b18ad25f396f9168302e36fb7e1e8923298ab3127da252d288d5af9d" +checksum = "0694ea59225b0c5f3cb405ff3f670e4828358ed26aec49dc352f730f0cb1a8a3" dependencies = [ "bech32", "bitcoin_hashes", @@ -825,9 +825,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4529658bdda7fd6769b8614be250cdcfc3aeb0ee72fe66f9e41e5e5eb73eac02" +checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" dependencies = [ "darling_core", "darling_macro", @@ -835,9 +835,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "649c91bc01e8b1eac09fb91e8dbc7d517684ca6be8ebc75bb9cafc894f9fdb6f" +checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f" dependencies = [ "fnv", "ident_case", @@ -849,9 +849,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5" +checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" dependencies = [ "darling_core", "quote", @@ -1416,9 +1416,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.51" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1652,9 +1652,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.136" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55edcf6c0bb319052dea84732cf99db461780fd5e8d3eb46ab6ff312ab31f197" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "link-cplusplus" @@ -1703,15 +1703,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - [[package]] name = "mime" version = "0.3.16" @@ -1804,8 +1795,6 @@ dependencies = [ "bitflags", "cfg-if 1.0.0", "libc", - "memoffset", - "pin-utils", ] [[package]] @@ -1973,7 +1962,6 @@ dependencies = [ "log", "mime", "mime_guess", - "nix", "ord-bitcoincore-rpc", "pretty_assertions", "pulldown-cmark", @@ -2022,9 +2010,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.3.0" +version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" [[package]] name = "output_vt100" @@ -2121,9 +2109,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "polling" diff --git a/Cargo.toml b/Cargo.toml index fc1ea7ec29..a5b2480125 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,6 @@ tower-http = { version = "0.3.3", features = ["cors"] } [dev-dependencies] executable-path = "1.0.0" -nix = "0.25.0" pretty_assertions = "1.2.1" tempfile = "3.2.0" test-bitcoincore-rpc = { path = "test-bitcoincore-rpc" } diff --git a/tests/command_builder.rs b/tests/command_builder.rs index 0b7eedcb90..8775c3bfba 100644 --- a/tests/command_builder.rs +++ b/tests/command_builder.rs @@ -1,10 +1,5 @@ use super::*; -enum ExpectedExitStatus { - Code(i32), - Signal(Signal), -} - pub(crate) struct Output { pub(crate) tempdir: TempDir, pub(crate) stdout: String, @@ -34,7 +29,7 @@ impl ToArgs for [&str; N] { pub(crate) struct CommandBuilder { args: Vec, - expected_exit_status: ExpectedExitStatus, + expected_exit_code: i32, expected_stderr: Expected, expected_stdout: Expected, rpc_server_url: Option, @@ -45,7 +40,7 @@ impl CommandBuilder { pub(crate) fn new(args: impl ToArgs) -> Self { Self { args: args.to_args(), - expected_exit_status: ExpectedExitStatus::Code(0), + expected_exit_code: 0, expected_stderr: Expected::String(String::new()), expected_stdout: Expected::String(String::new()), rpc_server_url: None, @@ -88,16 +83,9 @@ impl CommandBuilder { } } - pub(crate) fn expected_exit_code(self, expected_status: i32) -> Self { - Self { - expected_exit_status: ExpectedExitStatus::Code(expected_status), - ..self - } - } - - pub(crate) fn expected_exit_signal(self, expected_signal: Signal) -> Self { + pub(crate) fn expected_exit_code(self, expected_exit_code: i32) -> Self { Self { - expected_exit_status: ExpectedExitStatus::Signal(expected_signal), + expected_exit_code, ..self } } @@ -131,10 +119,7 @@ impl CommandBuilder { let stdout = str::from_utf8(&output.stdout).unwrap(); let stderr = str::from_utf8(&output.stderr).unwrap(); - if match self.expected_exit_status { - ExpectedExitStatus::Code(code) => output.status.code() != Some(code), - ExpectedExitStatus::Signal(signal) => output.status.signal() != Some(signal as i32), - } { + if output.status.code() != Some(self.expected_exit_code) { panic!( "Test failed: {}\nstdout:\n{}\nstderr:\n{}", output.status, stdout, stderr diff --git a/tests/lib.rs b/tests/lib.rs index c2a05e7537..d15aeba7f5 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -4,14 +4,12 @@ use { self::{command_builder::CommandBuilder, expected::Expected}, bitcoin::{blockdata::constants::COIN_VALUE, Network, OutPoint}, executable_path::executable_path, - nix::{sys::signal::Signal, unistd::Pid}, pretty_assertions::assert_eq as pretty_assert_eq, regex::Regex, reqwest::{StatusCode, Url}, std::{ fs, net::TcpListener, - os::unix::process::ExitStatusExt, process::{self, Child, Command, Stdio}, str, thread, time::Duration, diff --git a/tests/server.rs b/tests/server.rs index 0e3e342ec0..5cd606acbf 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -4,21 +4,32 @@ use super::*; fn run() { let rpc_server = test_bitcoincore_rpc::spawn(); - let builder = CommandBuilder::new("server") - .rpc_server(&rpc_server) - .expected_exit_signal(Signal::SIGINT); + let port = TcpListener::bind("127.0.0.1:0") + .unwrap() + .local_addr() + .unwrap() + .port(); + + let builder = CommandBuilder::new(format!("server --http-port {}", port)).rpc_server(&rpc_server); let mut command = builder.command(); let mut child = command.spawn().unwrap(); - nix::sys::signal::kill( - Pid::from_raw(child.id().try_into().unwrap()), - Signal::SIGINT, - ) - .unwrap(); + for attempt in 0.. { + if let Ok(response) = reqwest::blocking::get(format!("http://localhost:{port}/status")) { + if response.status() == 200 { + assert_eq!(response.text().unwrap(), "OK"); + break; + } + } - child.kill().unwrap(); + if attempt == 100 { + panic!("Server did not respond to status check",); + } - builder.check(child.wait_with_output().unwrap()); + thread::sleep(Duration::from_millis(50)); + } + + child.kill().unwrap(); }