...

Source file src/github.com/shirou/gopsutil/internal/common/sleep_test.go

Documentation: github.com/shirou/gopsutil/internal/common

     1  package common_test
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/shirou/gopsutil/internal/common"
    10  )
    11  
    12  func TestSleep(test *testing.T) {
    13  	const dt = 50 * time.Millisecond
    14  	var t = func(name string, ctx context.Context, expected error) {
    15  		test.Run(name, func(test *testing.T) {
    16  			var err = common.Sleep(ctx, dt)
    17  			if !errors.Is(err, expected) {
    18  				test.Errorf("expected %v, got %v", expected, err)
    19  			}
    20  		})
    21  	}
    22  
    23  	var ctx = context.Background()
    24  	var canceled, cancel = context.WithCancel(ctx)
    25  	cancel()
    26  
    27  	t("background context", ctx, nil)
    28  	t("canceled context", canceled, context.Canceled)
    29  }
    30  

View as plain text