1- import { assert , test } from 'vitest' ;
1+ import { test } from 'node:test' ;
2+ import assert from 'node:assert/strict' ;
23import { DockerClient } from '../lib/docker-client.js' ;
34
4- test ( 'concurrent requests should execute in parallel' , async ( ) => {
5- const client = await DockerClient . fromDockerConfig ( ) ;
6- const startTime = Date . now ( ) ;
7-
8- // Make 5 concurrent API calls
9- const promises = [
10- client . systemPing ( ) ,
11- client . systemInfo ( ) ,
12- client . systemVersion ( ) ,
13- client . containerList ( { all : true } ) ,
14- client . imageList ( ) ,
15- ] ;
16-
17- // Execute all requests concurrently
18- const results = await Promise . all ( promises ) ;
19- const totalTime = Date . now ( ) - startTime ;
20-
21- // Verify all requests completed successfully
22- assert . isNotNull ( results [ 0 ] ) ; // systemPing result
23- assert . isNotNull ( results [ 1 ] ) ; // systemInfo result
24- assert . isNotNull ( results [ 2 ] ) ; // systemVersion result
25- assert . isNotNull ( results [ 3 ] ) ; // containerList result
26- assert . isNotNull ( results [ 4 ] ) ; // imageList result
27-
28- console . log ( ` Completed 5 concurrent requests in ${ totalTime } ms` ) ;
29-
30- // Concurrent requests should be faster than sequential ones
31- // This is a rough check - concurrent should typically be < 80% of sequential time
32- assert . isTrue (
33- totalTime < 10000 ,
34- 'Concurrent requests should complete within reasonable time' ,
35- ) ;
36- } , 15000 ) ;
5+ test (
6+ 'concurrent requests should execute in parallel' ,
7+ { timeout : 15000 } ,
8+ async ( ) => {
9+ const client = await DockerClient . fromDockerConfig ( ) ;
10+ const startTime = Date . now ( ) ;
11+
12+ // Make 5 concurrent API calls
13+ const promises = [
14+ client . systemPing ( ) ,
15+ client . systemInfo ( ) ,
16+ client . systemVersion ( ) ,
17+ client . containerList ( { all : true } ) ,
18+ client . imageList ( ) ,
19+ ] ;
20+
21+ // Execute all requests concurrently
22+ const results = await Promise . all ( promises ) ;
23+ const totalTime = Date . now ( ) - startTime ;
24+
25+ // Verify all requests completed successfully
26+ assert . notStrictEqual ( results [ 0 ] , null ) ; // systemPing result
27+ assert . notStrictEqual ( results [ 1 ] , null ) ; // systemInfo result
28+ assert . notStrictEqual ( results [ 2 ] , null ) ; // systemVersion result
29+ assert . notStrictEqual ( results [ 3 ] , null ) ; // containerList result
30+ assert . notStrictEqual ( results [ 4 ] , null ) ; // imageList result
31+
32+ console . log ( ` Completed 5 concurrent requests in ${ totalTime } ms` ) ;
33+
34+ // Concurrent requests should be faster than sequential ones
35+ // This is a rough check - concurrent should typically be < 80% of sequential time
36+ assert . ok (
37+ totalTime < 10000 ,
38+ 'Concurrent requests should complete within reasonable time' ,
39+ ) ;
40+ } ,
41+ ) ;
3742
38- test ( 'high concurrency stress test' , async ( ) => {
43+ test ( 'high concurrency stress test' , { timeout : 20000 } , async ( ) => {
3944 const client = await DockerClient . fromDockerConfig ( ) ;
4045 const startTime = Date . now ( ) ;
4146
@@ -48,20 +53,24 @@ test('high concurrency stress test', async () => {
4853
4954 // Verify all requests completed successfully
5055 results . forEach ( ( result , index ) => {
51- assert . isNotNull ( result , `Request ${ index } should return a result` ) ;
56+ assert . notStrictEqual (
57+ result ,
58+ null ,
59+ `Request ${ index } should return a result` ,
60+ ) ;
5261 } ) ;
5362
5463 console . log ( ` Completed 20 concurrent ping requests in ${ totalTime } ms` ) ;
5564 console . log ( ` Average time per request: ${ ( totalTime / 20 ) . toFixed ( 1 ) } ms` ) ;
5665
5766 // All requests should complete within reasonable time
58- assert . isTrue (
67+ assert . ok (
5968 totalTime < 15000 ,
6069 'High concurrency requests should complete within reasonable time' ,
6170 ) ;
62- } , 20000 ) ;
71+ } ) ;
6372
64- test ( 'mixed concurrent operations' , async ( ) => {
73+ test ( 'mixed concurrent operations' , { timeout : 18000 } , async ( ) => {
6574 const client = await DockerClient . fromDockerConfig ( ) ;
6675
6776 // Test different types of concurrent operations
@@ -86,17 +95,18 @@ test('mixed concurrent operations', async () => {
8695
8796 // Verify all requests completed successfully
8897 results . forEach ( ( result , index ) => {
89- assert . isNotNull (
98+ assert . notStrictEqual (
9099 result ,
100+ null ,
91101 `Mixed operation ${ index } should return a result` ,
92102 ) ;
93103 } ) ;
94104
95105 console . log ( ` Completed 10 mixed concurrent operations in ${ totalTime } ms` ) ;
96106
97107 // Should handle mixed operations efficiently
98- assert . isTrue (
108+ assert . ok (
99109 totalTime < 12000 ,
100110 'Mixed concurrent operations should complete efficiently' ,
101111 ) ;
102- } , 18000 ) ;
112+ } ) ;
0 commit comments