@@ -408,60 +408,89 @@ func TestWorkspaceAgentListeningPorts(t *testing.T) {
408
408
CoordinatorDialer : agentClient .ListenWorkspaceAgentTailnet ,
409
409
Logger : slogtest .Make (t , nil ).Named ("agent" ).Leveled (slog .LevelDebug ),
410
410
})
411
- defer func () {
411
+ t . Cleanup ( func () {
412
412
_ = agentCloser .Close ()
413
- }( )
413
+ })
414
414
resources := coderdtest .AwaitWorkspaceAgents (t , client , workspace .LatestBuild .ID )
415
415
416
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
417
- defer cancel ()
416
+ t .Run ("LinuxAndWindows" , func (t * testing.T ) {
417
+ t .Parallel ()
418
+ if runtime .GOOS != "linux" && runtime .GOOS != "windows" {
419
+ t .Skip ("only runs on linux and windows" )
420
+ return
421
+ }
418
422
419
- // Create a TCP listener on a random port that we expect to see in the
420
- // response.
421
- l , err := net .Listen ("tcp" , "localhost:0" )
422
- require .NoError (t , err )
423
- defer l .Close ()
424
- tcpAddr , _ := l .Addr ().(* net.TCPAddr )
423
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
424
+ defer cancel ()
425
425
426
- // List ports and ensure that the port we expect to see is there.
427
- res , err := client .WorkspaceAgentListeningPorts (ctx , resources [0 ].Agents [0 ].ID )
428
- require .NoError (t , err )
426
+ // Create a TCP listener on a random port that we expect to see in the
427
+ // response.
428
+ l , err := net .Listen ("tcp" , "localhost:0" )
429
+ require .NoError (t , err )
430
+ defer l .Close ()
431
+ tcpAddr , _ := l .Addr ().(* net.TCPAddr )
429
432
430
- var (
431
- expected = map [uint16 ]bool {
432
- // expect the listener we made
433
- uint16 (tcpAddr .Port ): false ,
434
- // expect the coderdtest server
435
- uint16 (coderdPort ): false ,
436
- }
437
- )
438
- for _ , port := range res .Ports {
439
- if port .Network == codersdk .ListeningPortNetworkTCP {
440
- if val , ok := expected [port .Port ]; ok {
441
- if val {
442
- t .Fatalf ("expected to find TCP port %d only once in response" , port .Port )
433
+ // List ports and ensure that the port we expect to see is there.
434
+ res , err := client .WorkspaceAgentListeningPorts (ctx , resources [0 ].Agents [0 ].ID )
435
+ require .NoError (t , err )
436
+
437
+ var (
438
+ expected = map [uint16 ]bool {
439
+ // expect the listener we made
440
+ uint16 (tcpAddr .Port ): false ,
441
+ // expect the coderdtest server
442
+ uint16 (coderdPort ): false ,
443
+ }
444
+ )
445
+ for _ , port := range res .Ports {
446
+ if port .Network == codersdk .ListeningPortNetworkTCP {
447
+ if val , ok := expected [port .Port ]; ok {
448
+ if val {
449
+ t .Fatalf ("expected to find TCP port %d only once in response" , port .Port )
450
+ }
443
451
}
452
+ expected [port .Port ] = true
444
453
}
445
- expected [port .Port ] = true
446
454
}
447
- }
448
- for port , found := range expected {
449
- if ! found {
450
- t . Fatalf ( "expected to find TCP port %d in response" , port )
455
+ for port , found := range expected {
456
+ if ! found {
457
+ t . Fatalf ( "expected to find TCP port %d in response" , port )
458
+ }
451
459
}
452
- }
453
460
454
- // Close the listener and check that the port is no longer in the response.
455
- require .NoError (t , l .Close ())
456
- time .Sleep (2 * time .Second ) // avoid cache
457
- res , err = client .WorkspaceAgentListeningPorts (ctx , resources [0 ].Agents [0 ].ID )
458
- require .NoError (t , err )
461
+ // Close the listener and check that the port is no longer in the response.
462
+ require .NoError (t , l .Close ())
463
+ time .Sleep (2 * time .Second ) // avoid cache
464
+ res , err = client .WorkspaceAgentListeningPorts (ctx , resources [0 ].Agents [0 ].ID )
465
+ require .NoError (t , err )
459
466
460
- for _ , port := range res .Ports {
461
- if port .Network == codersdk .ListeningPortNetworkTCP && port .Port == uint16 (tcpAddr .Port ) {
462
- t .Fatalf ("expected to not find TCP port %d in response" , tcpAddr .Port )
467
+ for _ , port := range res .Ports {
468
+ if port .Network == codersdk .ListeningPortNetworkTCP && port .Port == uint16 (tcpAddr .Port ) {
469
+ t .Fatalf ("expected to not find TCP port %d in response" , tcpAddr .Port )
470
+ }
463
471
}
464
- }
472
+ })
473
+
474
+ t .Run ("Darwin" , func (t * testing.T ) {
475
+ t .Parallel ()
476
+ if runtime .GOOS != "darwin" {
477
+ t .Skip ("only runs on darwin" )
478
+ return
479
+ }
480
+
481
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
482
+ defer cancel ()
483
+
484
+ // Create a TCP listener on a random port.
485
+ l , err := net .Listen ("tcp" , "localhost:0" )
486
+ require .NoError (t , err )
487
+ defer l .Close ()
488
+
489
+ // List ports and ensure that the list is empty because we're on darwin.
490
+ res , err := client .WorkspaceAgentListeningPorts (ctx , resources [0 ].Agents [0 ].ID )
491
+ require .NoError (t , err )
492
+ require .Len (t , res .Ports , 0 )
493
+ })
465
494
}
466
495
467
496
func TestWorkspaceAgentAppHealth (t * testing.T ) {
0 commit comments