1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-24 13:48:56 +08:00

31 lines
643 B
Go
Raw Permalink Normal View History

// SPDX-License-Identifier: BSD-3-Clause
package common_test
import (
"context"
2021-12-04 22:29:38 +01:00
"errors"
"testing"
"time"
"github.com/shirou/gopsutil/v4/internal/common"
)
func TestSleep(test *testing.T) {
const dt = 50 * time.Millisecond
2021-12-22 21:54:41 +00:00
t := func(name string, ctx context.Context, expected error) {
test.Run(name, func(test *testing.T) {
2021-12-22 21:54:41 +00:00
err := common.Sleep(ctx, dt)
2021-12-04 22:29:38 +01:00
if !errors.Is(err, expected) {
test.Errorf("expected %v, got %v", expected, err)
}
})
}
2021-12-22 21:54:41 +00:00
ctx := context.Background()
canceled, cancel := context.WithCancel(ctx)
cancel()
t("background context", ctx, nil)
t("canceled context", canceled, context.Canceled)
}