test nonzero status
parent
1842023224
commit
1f7b222b9c
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue