Skip to content

Commit

Permalink
Move TBA match publishing from time of commit to time of showing score.
Browse files Browse the repository at this point in the history
Closes #16.
  • Loading branch information
patfair committed Aug 28, 2016
1 parent bc8a6ea commit 3cd216c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
32 changes: 16 additions & 16 deletions match_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ func MatchPlayShowResultHandler(w http.ResponseWriter, r *http.Request) {
mainArena.savedMatchResult = matchResult
mainArena.scorePostedNotifier.Notify(nil)

if eventSettings.TbaPublishingEnabled && match.Type != "practice" {
// Publish asynchronously to The Blue Alliance.
go func() {
err = PublishMatches()
if err != nil {
log.Printf("Failed to publish matches: %s", err.Error())
}
if match.Type == "qualification" {
err = PublishRankings()
if err != nil {
log.Printf("Failed to publish rankings: %s", err.Error())
}
}
}()
}

http.Redirect(w, r, "/match_play", 302)
}

Expand Down Expand Up @@ -505,22 +521,6 @@ func CommitMatchScore(match *Match, matchResult *MatchResult, loadToShowBuffer b
}
}

if eventSettings.TbaPublishingEnabled && match.Type != "practice" {
// Publish asynchronously to The Blue Alliance.
go func() {
err = PublishMatches()
if err != nil {
log.Printf("Failed to publish matches: %s", err.Error())
}
if match.Type == "qualification" {
err = PublishRankings()
if err != nil {
log.Printf("Failed to publish rankings: %s", err.Error())
}
}
}()
}

// Back up the database, but don't error out if it fails.
err = db.Backup(fmt.Sprintf("post_%s_match_%s", match.Type, match.DisplayName))
if err != nil {
Expand Down
22 changes: 11 additions & 11 deletions match_play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ func TestMatchPlayShowResult(t *testing.T) {
assert.Equal(t, 302, recorder.Code)
assert.Equal(t, match.Id, mainArena.savedMatch.Id)
assert.Equal(t, match.Id, mainArena.savedMatchResult.MatchId)

// Verify TBA publishing by checking the log for the expected failure messages.
tbaBaseUrl = "fakeurl"
eventSettings.TbaPublishingEnabled = true
var writer bytes.Buffer
log.SetOutput(&writer)
recorder = getHttpResponse(fmt.Sprintf("/match_play/%d/show_result", match.Id))
assert.Equal(t, 302, recorder.Code)
time.Sleep(time.Millisecond * 10) // Allow some time for the asynchronous publishing to happen.
assert.Contains(t, writer.String(), "Failed to publish matches")
assert.Contains(t, writer.String(), "Failed to publish rankings")
}

func TestMatchPlayErrors(t *testing.T) {
Expand Down Expand Up @@ -177,17 +188,6 @@ func TestCommitMatch(t *testing.T) {
assert.Equal(t, 3, matchResult.PlayNumber)
match, _ = db.GetMatchById(1)
assert.Equal(t, "T", match.Winner)

// Verify TBA publishing by checking the log for the expected failure messages.
tbaBaseUrl = "fakeurl"
eventSettings.TbaPublishingEnabled = true
var writer bytes.Buffer
log.SetOutput(&writer)
err = CommitMatchScore(match, matchResult, false)
assert.Nil(t, err)
time.Sleep(time.Millisecond * 10) // Allow some time for the asynchronous publishing to happen.
assert.Contains(t, writer.String(), "Failed to publish matches")
assert.Contains(t, writer.String(), "Failed to publish rankings")
}

func TestCommitEliminationTie(t *testing.T) {
Expand Down

0 comments on commit 3cd216c

Please sign in to comment.