@@ -844,16 +844,28 @@ describe('tcp', () => {
844
844
} ) ;
845
845
846
846
test ( 'tcp packets are sent immediately without delay' , async ( ) => {
847
- const stack = await createStack ( ) ;
847
+ const stack1 = await createStack ( ) ;
848
+ const stack2 = await createStack ( ) ;
848
849
849
- const listener = await stack . listenTcp ( {
850
- host : '127.0.0.1' ,
850
+ const tun1 = await stack1 . createTunInterface ( {
851
+ ip : '192.168.1.1/24' ,
852
+ } ) ;
853
+
854
+ const tun2 = await stack2 . createTunInterface ( {
855
+ ip : '192.168.1.2/24' ,
856
+ } ) ;
857
+
858
+ // Connect the two interfaces
859
+ tun1 . readable . pipeTo ( tun2 . writable ) ;
860
+ tun2 . readable . pipeTo ( tun1 . writable ) ;
861
+
862
+ const listener = await stack2 . listenTcp ( {
851
863
port : 8080 ,
852
864
} ) ;
853
865
854
866
const [ outbound , inbound ] = await Promise . all ( [
855
- stack . connectTcp ( {
856
- host : '127.0.0.1 ' ,
867
+ stack1 . connectTcp ( {
868
+ host : '192.168.1.2 ' ,
857
869
port : 8080 ,
858
870
} ) ,
859
871
nextValue ( listener ) ,
@@ -866,20 +878,20 @@ describe('tcp', () => {
866
878
867
879
// Record start time
868
880
const startTime = performance . now ( ) ;
869
-
881
+
870
882
// Write and read immediately
871
883
await outboundWriter . write ( data ) ;
872
884
const received = await inboundReader . read ( ) ;
873
885
874
886
// Record end time
875
887
const endTime = performance . now ( ) ;
876
-
888
+
877
889
expect ( received . value ) . toStrictEqual ( data ) ;
878
-
890
+
879
891
// Check timing - with tcp_output enabled, this should be very fast
880
892
// Without tcp_output, there would be a significant delay (~300ms)
881
893
const elapsed = endTime - startTime ;
882
- expect ( elapsed ) . toBeLessThan ( 200 ) ;
894
+ expect ( elapsed ) . toBeCloseTo ( 0 , - 1 ) ;
883
895
} ) ;
884
896
} ) ;
885
897
0 commit comments