github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ais/kalive_internal_test.go (about) 1 // Package ais provides core functionality for the AIStore object storage. 2 /* 3 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package ais 6 7 import ( 8 "testing" 9 "time" 10 ) 11 12 func TestHB(t *testing.T) { 13 hb := newHB(time.Millisecond * 10) 14 15 if !hb.TimedOut("unknown server") { 16 t.Fatal("None existing server should return timed out") 17 } 18 19 id1 := "1" 20 hb.HeardFrom(id1, 0 /*now*/) 21 time.Sleep(time.Millisecond * 1) 22 23 if hb.TimedOut(id1) { 24 t.Fatal("Expecting no timeout") 25 } 26 27 time.Sleep(time.Millisecond * 10) 28 29 if !hb.TimedOut(id1) { 30 t.Fatal("Expecting timeout") 31 } 32 33 hb.HeardFrom(id1, 0 /*now*/) 34 time.Sleep(time.Millisecond * 11) 35 hb.HeardFrom(id1, 0 /*now*/) 36 if hb.TimedOut(id1) { 37 t.Fatal("Expecting no timeout") 38 } 39 40 time.Sleep(time.Millisecond * 10) 41 id2 := "2" 42 hb.HeardFrom(id2, 0 /*now*/) 43 44 if hb.TimedOut(id2) { 45 t.Fatal("Expecting no timeout") 46 } 47 48 if !hb.TimedOut(id1) { 49 t.Fatal("Expecting timeout") 50 } 51 }