Skip to content

Commit d472022

Browse files
Merge pull request #105 from theseus-rs/correct-windows-hang
fix: correct bug where commands hang on windows when retrieving stdout/stderr
2 parents 480faa8 + 5e5aac0 commit d472022

38 files changed

+587
-196
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- linux-x64
2828
- macos-arm64
2929
- macos-x64
30-
#- windows-x64
30+
- windows-x64
3131

3232
include:
3333
- platform: linux-x64
@@ -36,8 +36,8 @@ jobs:
3636
os: macos-14
3737
- platform: macos-x64
3838
os: macos-13
39-
#- platform: windows-x64
40-
# os: windows-2022
39+
- platform: windows-x64
40+
os: windows-2022
4141

4242
steps:
4343
- name: Checkout source code
@@ -55,6 +55,17 @@ jobs:
5555
tool: grcov
5656

5757
- name: Tests
58+
if: ${{ !startsWith(matrix.os, 'ubuntu-') }}
59+
env:
60+
CARGO_TERM_COLOR: always
61+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
62+
RUST_LOG: "info,postgresql_archive=debug,postgresql_commands=debug,postgresql_embedded=debug"
63+
RUST_LOG_SPAN_EVENTS: full
64+
run: |
65+
cargo test
66+
67+
- name: Tests
68+
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
5869
env:
5970
CARGO_TERM_COLOR: always
6071
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

postgresql_commands/src/clusterdb.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,15 @@ mod tests {
274274
#[test]
275275
fn test_builder_from() {
276276
let command = ClusterDbBuilder::from(&TestSettings).build();
277+
#[cfg(not(target_os = "windows"))]
278+
let command_prefix = r#"PGPASSWORD="password" "./clusterdb" "#;
279+
#[cfg(target_os = "windows")]
280+
let command_prefix = r#"".\\clusterdb" "#;
281+
277282
assert_eq!(
278-
r#"PGPASSWORD="password" "./clusterdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
283+
format!(
284+
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
285+
),
279286
command.to_command_string()
280287
);
281288
}
@@ -300,9 +307,15 @@ mod tests {
300307
.pg_password("password")
301308
.maintenance_db("postgres")
302309
.build();
310+
#[cfg(not(target_os = "windows"))]
311+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
312+
#[cfg(target_os = "windows")]
313+
let command_prefix = String::new();
303314

304315
assert_eq!(
305-
r#"PGDATABASE="database" PGPASSWORD="password" "clusterdb" "--all" "--dbname" "dbname" "--echo" "--quiet" "--table" "table" "--verbose" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres""#,
316+
format!(
317+
r#"{command_prefix}"clusterdb" "--all" "--dbname" "dbname" "--echo" "--quiet" "--table" "table" "--verbose" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres""#
318+
),
306319
command.to_command_string()
307320
);
308321
}

postgresql_commands/src/createdb.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,15 @@ mod tests {
379379
#[test]
380380
fn test_builder_from() {
381381
let command = CreateDbBuilder::from(&TestSettings).build();
382+
#[cfg(not(target_os = "windows"))]
383+
let command_prefix = r#"PGPASSWORD="password" "./createdb" "#;
384+
#[cfg(target_os = "windows")]
385+
let command_prefix = r#"".\\createdb" "#;
386+
382387
assert_eq!(
383-
r#"PGPASSWORD="password" "./createdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
388+
format!(
389+
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
390+
),
384391
command.to_command_string()
385392
);
386393
}
@@ -413,9 +420,15 @@ mod tests {
413420
.dbname("testdb")
414421
.description("Test Database")
415422
.build();
423+
#[cfg(not(target_os = "windows"))]
424+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
425+
#[cfg(target_os = "windows")]
426+
let command_prefix = String::new();
416427

417428
assert_eq!(
418-
r#"PGDATABASE="database" PGPASSWORD="password" "createdb" "--tablespace" "pg_default" "--echo" "--encoding" "UTF8" "--locale" "en_US.UTF-8" "--lc-collate" "en_US.UTF-8" "--lc-ctype" "en_US.UTF-8" "--icu-locale" "en_US" "--icu-rules" "standard" "--locale-provider" "icu" "--owner" "postgres" "--strategy" "wal_log" "--template" "template0" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "testdb" "Test Database""#,
429+
format!(
430+
r#"{command_prefix}"createdb" "--tablespace" "pg_default" "--echo" "--encoding" "UTF8" "--locale" "en_US.UTF-8" "--lc-collate" "en_US.UTF-8" "--lc-ctype" "en_US.UTF-8" "--icu-locale" "en_US" "--icu-rules" "standard" "--locale-provider" "icu" "--owner" "postgres" "--strategy" "wal_log" "--template" "template0" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "testdb" "Test Database""#
431+
),
419432
command.to_command_string()
420433
);
421434
}

postgresql_commands/src/createuser.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,15 @@ mod tests {
456456
#[test]
457457
fn test_builder_from() {
458458
let command = CreateUserBuilder::from(&TestSettings).build();
459+
#[cfg(not(target_os = "windows"))]
460+
let command_prefix = r#"PGPASSWORD="password" "./createuser" "#;
461+
#[cfg(target_os = "windows")]
462+
let command_prefix = r#"".\\createuser" "#;
463+
459464
assert_eq!(
460-
r#"PGPASSWORD="password" "./createuser" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
465+
format!(
466+
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
467+
),
461468
command.to_command_string()
462469
);
463470
}
@@ -497,9 +504,15 @@ mod tests {
497504
.password()
498505
.pg_password("password")
499506
.build();
507+
#[cfg(not(target_os = "windows"))]
508+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
509+
#[cfg(target_os = "windows")]
510+
let command_prefix = String::new();
500511

501512
assert_eq!(
502-
r#"PGDATABASE="database" PGPASSWORD="password" "createuser" "--with-admin" "admin" "--connection-limit" "10" "--createdb" "--no-createdb" "--echo" "--member-of" "member" "--inherit" "--no-inherit" "--login" "--no-login" "--with-member" "member" "--pwprompt" "--createrole" "--no-createrole" "--superuser" "--no-superuser" "--valid-until" "2021-12-31" "--version" "--interactive" "--bypassrls" "--no-bypassrls" "--replication" "--no-replication" "--help" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password""#,
513+
format!(
514+
r#"{command_prefix}"createuser" "--with-admin" "admin" "--connection-limit" "10" "--createdb" "--no-createdb" "--echo" "--member-of" "member" "--inherit" "--no-inherit" "--login" "--no-login" "--with-member" "member" "--pwprompt" "--createrole" "--no-createrole" "--superuser" "--no-superuser" "--valid-until" "2021-12-31" "--version" "--interactive" "--bypassrls" "--no-bypassrls" "--replication" "--no-replication" "--help" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password""#
515+
),
503516
command.to_command_string()
504517
);
505518
}

postgresql_commands/src/dropdb.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,15 @@ mod tests {
259259
#[test]
260260
fn test_builder_from() {
261261
let command = DropDbBuilder::from(&TestSettings).build();
262+
#[cfg(not(target_os = "windows"))]
263+
let command_prefix = r#"PGPASSWORD="password" "./dropdb" "#;
264+
#[cfg(target_os = "windows")]
265+
let command_prefix = r#"".\\dropdb" "#;
266+
262267
assert_eq!(
263-
r#"PGPASSWORD="password" "./dropdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
268+
format!(
269+
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
270+
),
264271
command.to_command_string()
265272
);
266273
}
@@ -284,9 +291,15 @@ mod tests {
284291
.maintenance_db("postgres")
285292
.dbname("dbname")
286293
.build();
294+
#[cfg(not(target_os = "windows"))]
295+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
296+
#[cfg(target_os = "windows")]
297+
let command_prefix = String::new();
287298

288299
assert_eq!(
289-
r#"PGDATABASE="database" PGPASSWORD="password" "dropdb" "--echo" "--force" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "dbname""#,
300+
format!(
301+
r#"{command_prefix}"dropdb" "--echo" "--force" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "dbname""#
302+
),
290303
command.to_command_string()
291304
);
292305
}

postgresql_commands/src/dropuser.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,15 @@ mod tests {
223223
#[test]
224224
fn test_builder_from() {
225225
let command = DropUserBuilder::from(&TestSettings).build();
226+
#[cfg(not(target_os = "windows"))]
227+
let command_prefix = r#"PGPASSWORD="password" "./dropuser" "#;
228+
#[cfg(target_os = "windows")]
229+
let command_prefix = r#"".\\dropuser" "#;
230+
226231
assert_eq!(
227-
r#"PGPASSWORD="password" "./dropuser" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
232+
format!(
233+
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
234+
),
228235
command.to_command_string()
229236
);
230237
}
@@ -245,9 +252,15 @@ mod tests {
245252
.password()
246253
.pg_password("password")
247254
.build();
255+
#[cfg(not(target_os = "windows"))]
256+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
257+
#[cfg(target_os = "windows")]
258+
let command_prefix = String::new();
248259

249260
assert_eq!(
250-
r#"PGDATABASE="database" PGPASSWORD="password" "dropuser" "--echo" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password""#,
261+
format!(
262+
r#"{command_prefix}"dropuser" "--echo" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password""#
263+
),
251264
command.to_command_string()
252265
);
253266
}

postgresql_commands/src/ecpg.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,12 @@ mod tests {
230230
#[test]
231231
fn test_builder_from() {
232232
let command = EcpgBuilder::from(&TestSettings).build();
233-
assert_eq!(r#""./ecpg""#, command.to_command_string());
233+
#[cfg(not(target_os = "windows"))]
234+
let command_prefix = r#""./ecpg""#;
235+
#[cfg(target_os = "windows")]
236+
let command_prefix = r#"".\\ecpg""#;
237+
238+
assert_eq!(format!("{command_prefix}"), command.to_command_string());
234239
}
235240

236241
#[test]
@@ -250,9 +255,15 @@ mod tests {
250255
.version()
251256
.help()
252257
.build();
258+
#[cfg(not(target_os = "windows"))]
259+
let command_prefix = r#"PGDATABASE="database" "#;
260+
#[cfg(target_os = "windows")]
261+
let command_prefix = String::new();
253262

254263
assert_eq!(
255-
r#"PGDATABASE="database" "ecpg" "-c" "-C" "mode" "-D" "symbol" "-h" "-i" "-I" "directory" "-o" "outfile" "-r" "behavior" "--regression" "-t" "--version" "--help""#,
264+
format!(
265+
r#"{command_prefix}"ecpg" "-c" "-C" "mode" "-D" "symbol" "-h" "-i" "-I" "directory" "-o" "outfile" "-r" "behavior" "--regression" "-t" "--version" "--help""#
266+
),
256267
command.to_command_string()
257268
);
258269
}

postgresql_commands/src/initdb.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,13 @@ mod tests {
526526
#[test]
527527
fn test_builder_from() {
528528
let command = InitDbBuilder::from(&TestSettings).build();
529+
#[cfg(not(target_os = "windows"))]
530+
let command_prefix = r#""./initdb" "#;
531+
#[cfg(target_os = "windows")]
532+
let command_prefix = r#"".\\initdb" "#;
533+
529534
assert_eq!(
530-
r#""./initdb" "--username" "postgres""#,
535+
format!(r#"{command_prefix}"--username" "postgres""#),
531536
command.to_command_string()
532537
);
533538
}
@@ -572,9 +577,15 @@ mod tests {
572577
.version()
573578
.help()
574579
.build();
580+
#[cfg(not(target_os = "windows"))]
581+
let command_prefix = r#"PGDATABASE="database" "#;
582+
#[cfg(target_os = "windows")]
583+
let command_prefix = String::new();
575584

576585
assert_eq!(
577-
r#"PGDATABASE="database" "initdb" "--auth" "md5" "--auth-host" "md5" "--auth-local" "md5" "--pgdata" "pgdata" "--encoding" "UTF8" "--allow-group-access" "--icu-locale" "en_US" "--icu-rules" "phonebook" "--data-checksums" "--locale" "en_US" "--lc-collate" "en_US" "--lc-ctype" "en_US" "--lc-messages" "en_US" "--lc-monetary" "en_US" "--lc-numeric" "en_US" "--lc-time" "en_US" "--no-locale" "--locale-provider" "icu" "--pwfile" ".pwfile" "--text-search-config" "english" "--username" "postgres" "--pwprompt" "--waldir" "waldir" "--wal-segsize" "1" "--set" "timezone=UTC" "--debug" "--discard-caches" "--directory" "directory" "--no-clean" "--no-sync" "--no-instructions" "--show" "--sync-only" "--version" "--help""#,
586+
format!(
587+
r#"{command_prefix}"initdb" "--auth" "md5" "--auth-host" "md5" "--auth-local" "md5" "--pgdata" "pgdata" "--encoding" "UTF8" "--allow-group-access" "--icu-locale" "en_US" "--icu-rules" "phonebook" "--data-checksums" "--locale" "en_US" "--lc-collate" "en_US" "--lc-ctype" "en_US" "--lc-messages" "en_US" "--lc-monetary" "en_US" "--lc-numeric" "en_US" "--lc-time" "en_US" "--no-locale" "--locale-provider" "icu" "--pwfile" ".pwfile" "--text-search-config" "english" "--username" "postgres" "--pwprompt" "--waldir" "waldir" "--wal-segsize" "1" "--set" "timezone=UTC" "--debug" "--discard-caches" "--directory" "directory" "--no-clean" "--no-sync" "--no-instructions" "--show" "--sync-only" "--version" "--help""#
588+
),
578589
command.to_command_string()
579590
);
580591
}

postgresql_commands/src/oid2name.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,15 @@ mod tests {
260260
#[test]
261261
fn test_builder_from() {
262262
let command = Oid2NameBuilder::from(&TestSettings).build();
263+
#[cfg(not(target_os = "windows"))]
264+
let command_prefix = r#""./oid2name" "#;
265+
#[cfg(target_os = "windows")]
266+
let command_prefix = r#"".\\oid2name" "#;
267+
263268
assert_eq!(
264-
r#""./oid2name" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
269+
format!(
270+
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
271+
),
265272
command.to_command_string()
266273
);
267274
}
@@ -285,9 +292,15 @@ mod tests {
285292
.port(5432)
286293
.username("username")
287294
.build();
295+
#[cfg(not(target_os = "windows"))]
296+
let command_prefix = r#"PGDATABASE="database" "#;
297+
#[cfg(target_os = "windows")]
298+
let command_prefix = String::new();
288299

289300
assert_eq!(
290-
r#"PGDATABASE="database" "oid2name" "--filenode" "filenode" "--indexes" "--oid" "oid" "--quiet" "--tablespaces" "--system-objects" "--table" "table" "--version" "--extended" "--help" "--dbname" "dbname" "--host" "localhost" "--port" "5432" "--username" "username""#,
301+
format!(
302+
r#"{command_prefix}"oid2name" "--filenode" "filenode" "--indexes" "--oid" "oid" "--quiet" "--tablespaces" "--system-objects" "--table" "table" "--version" "--extended" "--help" "--dbname" "dbname" "--host" "localhost" "--port" "5432" "--username" "username""#
303+
),
291304
command.to_command_string()
292305
);
293306
}

postgresql_commands/src/pg_amcheck.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,15 @@ mod tests {
539539
#[test]
540540
fn test_builder_from() {
541541
let command = PgAmCheckBuilder::from(&TestSettings).build();
542+
#[cfg(not(target_os = "windows"))]
543+
let command_prefix = r#"PGPASSWORD="password" "./pg_amcheck" "#;
544+
#[cfg(target_os = "windows")]
545+
let command_prefix = r#"".\\pg_amcheck" "#;
546+
542547
assert_eq!(
543-
r#"PGPASSWORD="password" "./pg_amcheck" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
548+
format!(
549+
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
550+
),
544551
command.to_command_string()
545552
);
546553
}
@@ -586,9 +593,15 @@ mod tests {
586593
.install_missing()
587594
.help()
588595
.build();
596+
#[cfg(not(target_os = "windows"))]
597+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
598+
#[cfg(target_os = "windows")]
599+
let command_prefix = String::new();
589600

590601
assert_eq!(
591-
r#"PGDATABASE="database" PGPASSWORD="password" "pg_amcheck" "--all" "--database" "database" "--exclude-database" "exclude_database" "--index" "index" "--exclude-index" "exclude_index" "--relation" "relation" "--exclude-relation" "exclude_relation" "--schema" "schema" "--exclude-schema" "exclude_schema" "--table" "table" "--exclude-table" "exclude_table" "--no-dependent-indexes" "--no-dependent-toast" "--no-strict-names" "--exclude-toast-pointers" "--on-error-stop" "--skip" "skip" "--startblock" "start_block" "--endblock" "end_block" "--heapallindexed" "--parent-check" "--rootdescend" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password" "--maintenance-db" "maintenance_db" "--echo" "--jobs" "jobs" "--progress" "--verbose" "--version" "--install-missing" "--help""#,
602+
format!(
603+
r#"{command_prefix}"pg_amcheck" "--all" "--database" "database" "--exclude-database" "exclude_database" "--index" "index" "--exclude-index" "exclude_index" "--relation" "relation" "--exclude-relation" "exclude_relation" "--schema" "schema" "--exclude-schema" "exclude_schema" "--table" "table" "--exclude-table" "exclude_table" "--no-dependent-indexes" "--no-dependent-toast" "--no-strict-names" "--exclude-toast-pointers" "--on-error-stop" "--skip" "skip" "--startblock" "start_block" "--endblock" "end_block" "--heapallindexed" "--parent-check" "--rootdescend" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password" "--maintenance-db" "maintenance_db" "--echo" "--jobs" "jobs" "--progress" "--verbose" "--version" "--install-missing" "--help""#
604+
),
592605
command.to_command_string()
593606
);
594607
}

0 commit comments

Comments
 (0)