Skip to content

Commit

Permalink
server: Check verified result first in chooseResults()
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Nov 10, 2021
1 parent 18dc858 commit aef74f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions server/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ func (bsm *BroadcastSessionsManager) collectResults(submitResultsCh chan *Submit
if res.Err == nil && res.TranscodeResult != nil {
if res.Session.OrchestratorScore == common.Score_Trusted {
trustedResults = res
} else if res.Session == bsm.verifiedSession {
// verified result should always come first and therefore take the priority
untrustedResults = append([]*SubmitResult{res}, untrustedResults...)
} else {
untrustedResults = append(untrustedResults, res)
}
Expand Down
14 changes: 10 additions & 4 deletions server/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1689,16 +1689,22 @@ func TestCollectResults(t *testing.T) {
untrustedSess1.OrchestratorScore = common.Score_Untrusted
untrustedSess2 := StubBroadcastSession("untrustedTranscoder2")
untrustedSess2.OrchestratorScore = common.Score_Untrusted
bsm := bsmWithSessList([]*BroadcastSession{trustedSess, untrustedSess1, untrustedSess2})
untrustedSessVerified := StubBroadcastSession("untrustedTranscoderVerified")
untrustedSessVerified.OrchestratorScore = common.Score_Untrusted
bsm := bsmWithSessList([]*BroadcastSession{trustedSess, untrustedSess1, untrustedSess2, untrustedSessVerified})
bsm.sessionVerified(untrustedSessVerified)

resChan := make(chan *SubmitResult, 3)
resChan := make(chan *SubmitResult, 4)
resChan <- &SubmitResult{Session: untrustedSess1, TranscodeResult: &ReceivedTranscodeResult{}}
resChan <- &SubmitResult{Session: untrustedSessVerified, TranscodeResult: &ReceivedTranscodeResult{}}
resChan <- &SubmitResult{Session: untrustedSess2, TranscodeResult: &ReceivedTranscodeResult{}}
resChan <- &SubmitResult{Session: trustedSess, TranscodeResult: &ReceivedTranscodeResult{}}

trustedResult, untrustedResults, err := bsm.collectResults(resChan, 3)
trustedResult, untrustedResults, err := bsm.collectResults(resChan, 4)

assert.NoError(err)
assert.Equal(trustedSess, trustedResult.Session)
assert.Len(untrustedResults, 2)
assert.Len(untrustedResults, 3)
// the first result should always come from the verified session
assert.Equal(untrustedSessVerified, untrustedResults[0].Session)
}

0 comments on commit aef74f6

Please sign in to comment.