-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webrtc: wait for fin_ack for closing datachannel
- Loading branch information
Showing
13 changed files
with
625 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package swarm | ||
|
||
import ( | ||
"context" | ||
"sync/atomic" | ||
"testing" | ||
|
||
"github.com/libp2p/go-libp2p/core/network" | ||
"github.com/libp2p/go-libp2p/core/peerstore" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type asyncStreamWrapper struct { | ||
network.MuxedStream | ||
beforeClose func() | ||
} | ||
|
||
func (s *asyncStreamWrapper) AsyncClose(onDone func()) error { | ||
s.beforeClose() | ||
err := s.Close() | ||
onDone() | ||
return err | ||
} | ||
|
||
func TestStreamAsyncCloser(t *testing.T) { | ||
s1 := makeSwarm(t) | ||
s2 := makeSwarm(t) | ||
|
||
s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), peerstore.TempAddrTTL) | ||
s, err := s1.NewStream(context.Background(), s2.LocalPeer()) | ||
require.NoError(t, err) | ||
ss, ok := s.(*Stream) | ||
require.True(t, ok) | ||
|
||
var called atomic.Bool | ||
as := &asyncStreamWrapper{ | ||
MuxedStream: ss.stream, | ||
beforeClose: func() { | ||
called.Store(true) | ||
}, | ||
} | ||
ss.stream = as | ||
ss.Close() | ||
require.True(t, called.Load()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.