@@ -8,6 +8,7 @@ import { timeout } from "./Timeout";
8
8
import { Channel } from "../Channel" ;
9
9
import CancellationToken from "cancellationtoken" ;
10
10
import * as assert from "assert" ;
11
+ import { nextTick } from "process" ;
11
12
12
13
[ 1 , 2 , 3 ] . forEach ( protocolMajorVersion => {
13
14
describe ( `MultiplexingStream v${ protocolMajorVersion } ` , ( ) => {
@@ -114,6 +115,24 @@ import * as assert from "assert";
114
115
await assert . rejects ( offer ) ;
115
116
} ) ;
116
117
118
+ it ( "Channel offer is canceled by sender after receiver gets it" , async ( ) => {
119
+ // Arrange to cancel the offer only after the remote party receives it (but before they accept it.)
120
+ const cts = CancellationToken . create ( ) ;
121
+ mx2 . on ( 'channelOffered' , args => {
122
+ cts . cancel ( 'rescind offer' ) ;
123
+ } ) ;
124
+ const offer = mx1 . offerChannelAsync ( "test" , undefined , cts . token ) ;
125
+ await expectAsync ( offer ) . toBeRejected ( )
126
+
127
+ // Give time for the termination fram to arrive *before* we try to accept the channel.
128
+ for ( let i = 0 ; i < 100 ; i ++ ) {
129
+ await new Promise < void > ( resolve => nextTick ( ( ) => resolve ( ) ) ) ;
130
+ }
131
+
132
+ // We expect this to timeout. But we need this for the test to fail if we have unobserved promise rejections.
133
+ await expectAsync ( timeout ( mx2 . acceptChannelAsync ( 'test' ) , 1000 ) ) . toBeRejected ( ) ;
134
+ } ) ;
135
+
117
136
it ( "Channel offer is rejected by event handler" , async ( ) => {
118
137
const handler = new Deferred < void > ( ) ;
119
138
mx2 . on ( "channelOffered" , ( args ) => {
0 commit comments