From a919cb077ebbad2dfebb042813685d3a9677b1c5 Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Sat, 5 Nov 2016 15:51:50 -0700 Subject: [PATCH] Revert "Move TBA match publishing from time of commit to time of showing score. Closes #16." Fixes #36 but reopens #16. This reverts commit 3cd216cbf417951bf3f2f5c6816186a49bc32e57. --- match_play.go | 52 +++++++++++++++++++++++----------------------- match_play_test.go | 28 ++++++++++++------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/match_play.go b/match_play.go index c6d2f1f..44acede 100644 --- a/match_play.go +++ b/match_play.go @@ -154,32 +154,6 @@ 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()) - } - } - }() - } - - if eventSettings.StemTvPublishingEnabled && match.Type != "practice" { - // Publish asynchronously to STEMtv. - go func() { - err = PublishMatchVideoSplit(match, time.Now()) - if err != nil { - log.Printf("Failed to publish match video split to STEMtv: %s", err.Error()) - } - }() - } - http.Redirect(w, r, "/match_play", 302) } @@ -531,6 +505,32 @@ 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()) + } + } + }() + } + + if eventSettings.StemTvPublishingEnabled && match.Type != "practice" { + // Publish asynchronously to STEMtv. + go func() { + err = PublishMatchVideoSplit(match, time.Now()) + if err != nil { + log.Printf("Failed to publish match video split to STEMtv: %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 { diff --git a/match_play_test.go b/match_play_test.go index b97be52..0b61aff 100644 --- a/match_play_test.go +++ b/match_play_test.go @@ -121,20 +121,6 @@ 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 and STEMtv publishing by checking the log for the expected failure messages. - tbaBaseUrl = "fakeurl" - stemTvBaseUrl = "fakeurl" - eventSettings.TbaPublishingEnabled = true - eventSettings.StemTvPublishingEnabled = 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") - assert.Contains(t, writer.String(), "Failed to publish match video split to STEMtv") } func TestMatchPlayErrors(t *testing.T) { @@ -192,6 +178,20 @@ func TestCommitMatch(t *testing.T) { assert.Equal(t, 3, matchResult.PlayNumber) match, _ = db.GetMatchById(1) assert.Equal(t, "T", match.Winner) + + // Verify TBA and STEMtv publishing by checking the log for the expected failure messages. + tbaBaseUrl = "fakeurl" + stemTvBaseUrl = "fakeurl" + eventSettings.TbaPublishingEnabled = true + eventSettings.StemTvPublishingEnabled = 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") + assert.Contains(t, writer.String(), "Failed to publish match video split to STEMtv") } func TestCommitEliminationTie(t *testing.T) {