From 1f7b222b9c9ec3b45b4f4c32c5fb7c78da0d50bd Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Mon, 27 Mar 2023 06:58:21 -0600 Subject: [PATCH] test nonzero status --- src/device/input/parse/v01/server.go | 6 +++--- src/device/input/parse/v01/server_test.go | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/device/input/parse/v01/server.go b/src/device/input/parse/v01/server.go index 0b58e62..13a1fb8 100644 --- a/src/device/input/parse/v01/server.go +++ b/src/device/input/parse/v01/server.go @@ -182,14 +182,14 @@ func (v01 *V01) serveGMStatus(w http.ResponseWriter, r *http.Request) { users := map[string]struct { Lag time.Duration `yaml:"lag,omitempty"` Player int `yaml:"player,omitempty"` - IdleFor time.Duration `yaml:"last_activity,omitempty"` + IdleFor time.Duration `yaml:"idle_for,omitempty"` }{} for k, v := range v01.cfg.Users { v2 := users[k] - v2.Lag = time.Duration(v.LastLag) / time.Millisecond + v2.Lag = time.Duration(v.LastLag) * time.Millisecond v2.Player = v.Player if v.LastTSMS > 0 { - v2.IdleFor = time.Since(time.Unix(0, v.LastTSMS/int64(time.Millisecond))) + v2.IdleFor = time.Since(time.Unix(0, v.LastTSMS*int64(time.Millisecond))) } users[k] = v2 } diff --git a/src/device/input/parse/v01/server_test.go b/src/device/input/parse/v01/server_test.go index 2de15f2..d2e73c8 100644 --- a/src/device/input/parse/v01/server_test.go +++ b/src/device/input/parse/v01/server_test.go @@ -10,6 +10,7 @@ import ( "strings" "sync" "testing" + "time" "gopkg.in/yaml.v2" ) @@ -92,8 +93,8 @@ func TestServeGM(t *testing.T) { var result struct { Players int `yaml:"Players"` Users map[string]struct { - Lag string - LastActivity string + Lag string + IdleFor string `yaml:"idle_for"` } `yaml:"Users"` } @@ -122,7 +123,10 @@ func TestServeGM(t *testing.T) { {}, } v01.cfg.Users = map[string]configUser{ - "bel": configUser{}, + "bel": configUser{ + LastTSMS: time.Now().Add(-1*time.Minute).UnixNano() / int64(time.Millisecond), + LastLag: int64(time.Second / time.Millisecond), + }, "zach": configUser{}, "chase": configUser{}, "mason": configUser{}, @@ -144,6 +148,16 @@ func TestServeGM(t *testing.T) { if len(result.Users) != 7 { t.Error(result.Users) } + if d, err := time.ParseDuration(result.Users["bel"].Lag); err != nil { + t.Error(err) + } else if d != time.Second { + t.Error(d) + } + if d, err := time.ParseDuration(result.Users["bel"].IdleFor); err != nil { + t.Error(err) + } else if d < time.Minute || d > 2*time.Minute { + t.Error(d) + } }) })