test nonzero status

master
Bel LaPointe 2023-03-27 06:58:21 -06:00
parent 1842023224
commit 1f7b222b9c
2 changed files with 20 additions and 6 deletions

View File

@ -182,14 +182,14 @@ func (v01 *V01) serveGMStatus(w http.ResponseWriter, r *http.Request) {
users := map[string]struct { users := map[string]struct {
Lag time.Duration `yaml:"lag,omitempty"` Lag time.Duration `yaml:"lag,omitempty"`
Player int `yaml:"player,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 { for k, v := range v01.cfg.Users {
v2 := users[k] v2 := users[k]
v2.Lag = time.Duration(v.LastLag) / time.Millisecond v2.Lag = time.Duration(v.LastLag) * time.Millisecond
v2.Player = v.Player v2.Player = v.Player
if v.LastTSMS > 0 { 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 users[k] = v2
} }

View File

@ -10,6 +10,7 @@ import (
"strings" "strings"
"sync" "sync"
"testing" "testing"
"time"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -92,8 +93,8 @@ func TestServeGM(t *testing.T) {
var result struct { var result struct {
Players int `yaml:"Players"` Players int `yaml:"Players"`
Users map[string]struct { Users map[string]struct {
Lag string Lag string
LastActivity string IdleFor string `yaml:"idle_for"`
} `yaml:"Users"` } `yaml:"Users"`
} }
@ -122,7 +123,10 @@ func TestServeGM(t *testing.T) {
{}, {},
} }
v01.cfg.Users = map[string]configUser{ 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{}, "zach": configUser{},
"chase": configUser{}, "chase": configUser{},
"mason": configUser{}, "mason": configUser{},
@ -144,6 +148,16 @@ func TestServeGM(t *testing.T) {
if len(result.Users) != 7 { if len(result.Users) != 7 {
t.Error(result.Users) 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)
}
}) })
}) })