Skip to content

Commit

Permalink
fixup! server: fix bug#1 in #1743
Browse files Browse the repository at this point in the history
  • Loading branch information
jailuthra committed Jan 28, 2021
1 parent 9cd662e commit b4a1a60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion server/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,21 @@ func TestSelectSession_MultipleInFlight(t *testing.T) {
assert.Len(bsm.lastSess.SegsInFlight, 0)
assert.Len(bsm.sessList(), 2)

// Same as above but to check thread safety, run this under -race
var wg sync.WaitGroup
wg.Add(2)
go func() { sess0 = sendSegStub(); wg.Done() }()
go func() { sess1 = sendSegStub(); wg.Done() }()
assert.True(wgWait(&wg), "Segment sending timed out")
assert.Equal(bsm.lastSess, sess0)
assert.Equal(sess0, sess1)
assert.Len(bsm.lastSess.SegsInFlight, 2)
wg.Add(2)
go func() { completeSegStub(sess0); wg.Done() }()
go func() { completeSegStub(sess1); wg.Done() }()
assert.True(wgWait(&wg), "Segment completion timed out")
assert.Len(bsm.lastSess.SegsInFlight, 0)

// send in multiple segments with delay > segDur to trigger O switch
sess0 = sendSegStub()
assert.Equal(bsm.lastSess, sess0)
Expand Down Expand Up @@ -433,6 +448,8 @@ func TestSelectSession_MultipleInFlight(t *testing.T) {
// send in multiple segments with delay > 2*segDur and only a single session available
bsm.suspendOrch(expectedSess0)
bsm.removeSession(expectedSess0)
assert.Len(bsm.sessMap, 1)

sess0 = sendSegStub()
assert.Equal(bsm.lastSess, sess0)
assert.Equal(expectedSess1.OrchestratorInfo, sess0.OrchestratorInfo)
Expand All @@ -445,11 +462,14 @@ func TestSelectSession_MultipleInFlight(t *testing.T) {
assert.Nil(bsm.lastSess)

completeSegStub(sess0)
assert.Len(bsm.sessList(), 1)

// remove both session and check if selector returns nil and sets lastSession to nil
bsm.suspendOrch(expectedSess0)
bsm.suspendOrch(expectedSess1)
bsm.removeSession(expectedSess0)
bsm.removeSession(expectedSess1)
assert.Len(bsm.sessMap, 0)

sess0 = sendSegStub()
assert.Nil(sess0)
assert.Nil(bsm.lastSess)
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cd ..
# Be more strict with HTTP push tests: run with race detector enabled
cd server
go test -run Push_ -race
go test -run TestSelectSession_ -race
go test -run RegisterConnection -race
cd ..

Expand Down

0 comments on commit b4a1a60

Please sign in to comment.