diff --git a/field/display.go b/field/display.go index 9ddba2f..dbda76d 100644 --- a/field/display.go +++ b/field/display.go @@ -7,7 +7,6 @@ package field import ( "fmt" - "math/rand" "net/url" "reflect" "sort" @@ -18,7 +17,6 @@ import ( const ( minDisplayId = 100 - maxDisplayId = 999 ) type DisplayType int @@ -136,11 +134,12 @@ func (arena *Arena) NextDisplayId() string { // Loop until we get an ID that isn't already used. This is inefficient if there is a large number of displays, but // that should never be the case. + candidateId := minDisplayId for { - candidateId := strconv.Itoa(rand.Intn(maxDisplayId+1-minDisplayId) + minDisplayId) - if _, ok := arena.Displays[candidateId]; !ok { - return candidateId + if _, ok := arena.Displays[strconv.Itoa(candidateId)]; !ok { + return strconv.Itoa(candidateId) } + candidateId++ } } @@ -194,8 +193,7 @@ func (arena *Arena) MarkDisplayDisconnected(display *Display) { delete(arena.Displays, existingDisplay.Id) } else { existingDisplay.ConnectionCount -= 1 - arena.DisplayConfigurationNotifier.Notify() - } + arena.DisplayConfigurationNotifier.Notify() } } diff --git a/field/display_test.go b/field/display_test.go index bf25879..b39b48f 100644 --- a/field/display_test.go +++ b/field/display_test.go @@ -59,12 +59,11 @@ func TestDisplayToUrl(t *testing.T) { func TestNextDisplayId(t *testing.T) { arena := setupTestArena(t) - assert.Equal(t, "874", arena.NextDisplayId()) + assert.Equal(t, "100", arena.NextDisplayId()) - // The next random numbers for the test seed are 514 and 653; check that a number is skipped if already used. - display := &Display{Id: "514"} + display := &Display{Id: "100"} arena.RegisterDisplay(display) - assert.Equal(t, "653", arena.NextDisplayId()) + assert.Equal(t, "101", arena.NextDisplayId()) } func TestDisplayRegisterUnregister(t *testing.T) { diff --git a/web/alliance_station_display_test.go b/web/alliance_station_display_test.go index c3078f3..eb25969 100644 --- a/web/alliance_station_display_test.go +++ b/web/alliance_station_display_test.go @@ -17,7 +17,7 @@ func TestAllianceStationDisplay(t *testing.T) { recorder := web.getHttpResponse("/displays/alliance_station") assert.Equal(t, 302, recorder.Code) - assert.Contains(t, recorder.Header().Get("Location"), "displayId=874") + assert.Contains(t, recorder.Header().Get("Location"), "displayId=100") assert.Contains(t, recorder.Header().Get("Location"), "station=R1") recorder = web.getHttpResponse("/displays/alliance_station?displayId=1&station=B1") diff --git a/web/audience_display_test.go b/web/audience_display_test.go index 9a18bba..2cdd874 100644 --- a/web/audience_display_test.go +++ b/web/audience_display_test.go @@ -15,7 +15,7 @@ func TestAudienceDisplay(t *testing.T) { recorder := web.getHttpResponse("/displays/audience") assert.Equal(t, 302, recorder.Code) - assert.Contains(t, recorder.Header().Get("Location"), "displayId=874") + assert.Contains(t, recorder.Header().Get("Location"), "displayId=100") assert.Contains(t, recorder.Header().Get("Location"), "background=%230f0") assert.Contains(t, recorder.Header().Get("Location"), "reversed=false") diff --git a/web/placeholder_display_test.go b/web/placeholder_display_test.go index f362064..ef432d7 100644 --- a/web/placeholder_display_test.go +++ b/web/placeholder_display_test.go @@ -16,7 +16,7 @@ func TestPlaceholderDisplay(t *testing.T) { recorder := web.getHttpResponse("/displays/audience") assert.Equal(t, 302, recorder.Code) - assert.Contains(t, recorder.Header().Get("Location"), "displayId=874") + assert.Contains(t, recorder.Header().Get("Location"), "displayId=100") recorder = web.getHttpResponse("/display?displayId=1") assert.Equal(t, 200, recorder.Code)