blob: 60f9866d5c1c6dcc9bba5a89313ab67e83877278 [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 rpc
import (
"testing"
"time"
)
func TestTimer(t *testing.T) {
test := newTimer(time.Millisecond)
if _, ok := <-test.C; ok {
t.Errorf("Expected the channel to be closed.")
}
// Test resetting.
test = newTimer(time.Hour)
if reset := test.Reset(time.Millisecond); !reset {
t.Errorf("Expected to successfully reset.")
}
if _, ok := <-test.C; ok {
t.Errorf("Expected the channel to be closed.")
}
// Test stop.
test = newTimer(100 * time.Millisecond)
test.Stop()
select {
case <-test.C:
t.Errorf("the test timer should have been stopped.")
case <-time.After(200 * time.Millisecond):
}
}