fixed persistence error and error with clients sometimes not showing up as connected.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"overlord-client/cmd/agent/config"
|
||||
rt "overlord-client/cmd/agent/runtime"
|
||||
@@ -18,6 +19,7 @@ func TestHandlePing(t *testing.T) {
|
||||
Conn: writer,
|
||||
Cfg: config.Config{},
|
||||
}
|
||||
env.SetLastPong(0)
|
||||
|
||||
ctx := context.Background()
|
||||
envelope := map[string]interface{}{
|
||||
@@ -44,6 +46,13 @@ func TestHandlePing(t *testing.T) {
|
||||
if pong.TS != expectedTS {
|
||||
t.Errorf("Expected timestamp %d, got %d", expectedTS, pong.TS)
|
||||
}
|
||||
|
||||
if env.LastPong().IsZero() {
|
||||
t.Fatalf("expected LastPong to be updated on ping")
|
||||
}
|
||||
if time.Since(env.LastPong()) > 5*time.Second {
|
||||
t.Fatalf("expected LastPong to be recent, got %s", env.LastPong())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleCommand_Ping(t *testing.T) {
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func HandlePing(ctx context.Context, env *runtime.Env, envelope map[string]interface{}) error {
|
||||
env.SetLastPong(time.Now().UnixMilli())
|
||||
|
||||
ts := extractTimestamp(envelope["ts"])
|
||||
if ts == 0 {
|
||||
ts = time.Now().UnixMilli()
|
||||
|
||||
Reference in New Issue
Block a user