blob: c061f00f55237b330fbb00e1bfb5f8b6d9bbade5 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mounttablelib
import (
"reflect"
"testing"
"time"
"v.io/v23/naming"
vdltime "v.io/v23/vdlroot/time"
)
func TestServerList(t *testing.T) {
eps := []string{
"endpoint:adfasdf@@who",
"endpoint:sdfgsdfg@@x/",
"endpoint:sdfgsdfg@@y",
"endpoint:dfgsfdg@@",
}
// Test adding entries.
ft := NewFakeTimeClock()
SetServerListClock(ft)
sl := newServerList()
for i, ep := range eps {
sl.add(ep, time.Duration(5*i)*time.Second)
}
if sl.len() != len(eps) {
t.Fatalf("got %d, want %d", sl.len(), len(eps))
}
// Test timing out entries.
ft.Advance(6 * time.Second)
if numLeft, _ := sl.removeExpired(); numLeft != len(eps)-2 {
t.Fatalf("got %d, want %d", sl.len(), len(eps)-2)
}
// Test removing entries.
sl.remove(eps[2])
if sl.len() != len(eps)-3 {
t.Fatalf("got %d, want %d", sl.len(), len(eps)-3)
}
// Test copyToSlice.
if got, want := sl.copyToSlice(), []naming.MountedServer{
{
Server: "endpoint:dfgsfdg@@",
Deadline: vdltime.Deadline{now.Add(15 * time.Second)},
},
}; !reflect.DeepEqual(got, want) {
t.Errorf("Got %v, want %v", got, want)
}
}