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 . ok ( results [ 0 ] ) ; // systemPing result
27+ assert . ok ( results [ 1 ] ) ; // systemInfo result
28+ assert . ok ( results [ 2 ] ) ; // systemVersion result
29+ assert . ok ( results [ 3 ] ) ; // containerList result
30+ assert . ok ( results [ 4 ] ) ; // 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,20 @@ 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 . ok ( result , `Request ${ index } should return a result` ) ;
5257 } ) ;
5358
5459 console . log ( ` Completed 20 concurrent ping requests in ${ totalTime } ms` ) ;
5560 console . log ( ` Average time per request: ${ ( totalTime / 20 ) . toFixed ( 1 ) } ms` ) ;
5661
5762 // All requests should complete within reasonable time
58- assert . isTrue (
63+ assert . ok (
5964 totalTime < 15000 ,
6065 'High concurrency requests should complete within reasonable time' ,
6166 ) ;
62- } , 20000 ) ;
67+ } ) ;
6368
64- test ( 'mixed concurrent operations' , async ( ) => {
69+ test ( 'mixed concurrent operations' , { timeout : 18000 } , async ( ) => {
6570 const client = await DockerClient . fromDockerConfig ( ) ;
6671
6772 // Test different types of concurrent operations
@@ -86,17 +91,14 @@ test('mixed concurrent operations', async () => {
8691
8792 // Verify all requests completed successfully
8893 results . forEach ( ( result , index ) => {
89- assert . isNotNull (
90- result ,
91- `Mixed operation ${ index } should return a result` ,
92- ) ;
94+ assert . ok ( result , `Mixed operation ${ index } should return a result` ) ;
9395 } ) ;
9496
9597 console . log ( ` Completed 10 mixed concurrent operations in ${ totalTime } ms` ) ;
9698
9799 // Should handle mixed operations efficiently
98- assert . isTrue (
100+ assert . ok (
99101 totalTime < 12000 ,
100102 'Mixed concurrent operations should complete efficiently' ,
101103 ) ;
102- } , 18000 ) ;
104+ } ) ;
0 commit comments