Skip to content

Commit

Permalink
Enable CI for Windows (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Oct 28, 2022
1 parent 073d37e commit b2b80ed
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* -text
8 changes: 7 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ jobs:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- ubuntu-latest
- windows-latest

runs-on: ${{matrix.os}}

Expand All @@ -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

Expand Down
50 changes: 19 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
25 changes: 5 additions & 20 deletions tests/command_builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use super::*;

enum ExpectedExitStatus {
Code(i32),
Signal(Signal),
}

pub(crate) struct Output {
pub(crate) tempdir: TempDir,
pub(crate) stdout: String,
Expand Down Expand Up @@ -34,7 +29,7 @@ impl<const N: usize> ToArgs for [&str; N] {

pub(crate) struct CommandBuilder {
args: Vec<String>,
expected_exit_status: ExpectedExitStatus,
expected_exit_code: i32,
expected_stderr: Expected,
expected_stdout: Expected,
rpc_server_url: Option<String>,
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 21 additions & 10 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit b2b80ed

Please sign in to comment.