Skip to content

Commit

Permalink
Fix timeout error with TestStreamClose
Browse files Browse the repository at this point in the history
Relates to pion#187
  • Loading branch information
enobufs authored and jerry-tao committed Oct 13, 2022
1 parent 727e2aa commit 04aa282
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,7 @@ func (a *Association) sendResetRequest(streamIdentifier uint16) error {
func (a *Association) handleReconfigParam(raw param) (*packet, error) {
switch p := raw.(type) {
case *paramOutgoingResetRequest:
a.log.Tracef("[%s] handleReconfigParam (OutgoingResetRequest)", a.name)
a.reconfigRequests[p.reconfigRequestSequenceNumber] = p
resp := a.resetStreamsIfAny(p)
if resp != nil {
Expand All @@ -1993,6 +1994,7 @@ func (a *Association) handleReconfigParam(raw param) (*packet, error) {
return nil, nil //nolint:nilnil

case *paramReconfigResponse:
a.log.Tracef("[%s] handleReconfigParam (ReconfigResponse)", a.name)
delete(a.reconfigs, p.reconfigResponseSequenceNumber)
if len(a.reconfigs) == 0 {
a.tReconfig.stop()
Expand Down
6 changes: 6 additions & 0 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,9 @@ func (s *Stream) onInboundStreamReset() {
s.state = StreamStateClosed
}
}

func (s *Stream) State() StreamState {
s.lock.RLock()
defer s.lock.RUnlock()
return s.state
}
22 changes: 18 additions & 4 deletions vnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,20 @@ func TestStreamClose(t *testing.T) {
if !assert.NoError(t, err, "should succeed") {
return
}
defer stream.Close() // nolint:errcheck
assert.Equal(t, StreamStateOpen, stream.State())

buf := make([]byte, 1500)
for {
n, err := stream.Read(buf)
if err != nil {
t.Logf("server: Read returned %v", err)
log.Infof("server: Read returned %v", err)
stream.Close() // nolint:errcheck

assert.Equal(t, StreamStateClosed, stream.State())

// give a bit of time for the OutgoingResetRequest so that
// the client side stream.Read() will return with EOF.
time.Sleep(100 * time.Millisecond)
break
}

Expand Down Expand Up @@ -481,14 +488,19 @@ func TestStreamClose(t *testing.T) {
if !assert.NoError(t, err, "should succeed") {
return
}
defer assoc.Close() // nolint:errcheck
defer func() {
log.Info("closing client side association")
assoc.Close() // nolint:errcheck
log.Info("closed client side association")
}()

log.Info("client handshake complete")

stream, err := assoc.OpenStream(777, PayloadTypeWebRTCBinary)
if !assert.NoError(t, err, "should succeed") {
return
}
assert.Equal(t, StreamStateOpen, stream.State())

stream.SetReliabilityParams(false, ReliabilityTypeReliable, 0)

Expand All @@ -505,7 +517,8 @@ func TestStreamClose(t *testing.T) {
log.Info("client read")
_, err2 := stream.Read(buf)
if err2 != nil {
t.Logf("client: Read returned %v", err2)
log.Infof("client: Read returned %v", err2)
assert.Equal(t, StreamStateClosed, stream.State())
break
}
}
Expand All @@ -522,6 +535,7 @@ func TestStreamClose(t *testing.T) {

err = stream.Close()
assert.NoError(t, err, "should succeed")
assert.Equal(t, StreamStateClosing, stream.State())

log.Info("client wait for exit reading..")
<-done
Expand Down

0 comments on commit 04aa282

Please sign in to comment.