From e9c1f000f465e8dedfe486c6f3f6cb1addf0e68a Mon Sep 17 00:00:00 2001 From: photostorm Date: Sat, 28 Oct 2023 18:11:18 -0400 Subject: [PATCH] added DeadlineHolder --- doc.go | 4 ++++ io_test.go | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc.go b/doc.go index 0cfb503..989e286 100644 --- a/doc.go +++ b/doc.go @@ -19,6 +19,10 @@ func Open() (Pty, Tty, error) { // FdHolder surfaces the Fd() method of the underlying handle. type FdHolder interface { Fd() uintptr +} + +// DeadlineHolder surfaces the SetDeadline() method to sets the read and write deadlines. +type DeadlineHolder interface { SetDeadline(t time.Time) error } diff --git a/io_test.go b/io_test.go index 9fb682e..cc18ccd 100644 --- a/io_test.go +++ b/io_test.go @@ -27,12 +27,14 @@ var mu sync.Mutex func TestReadDeadline(t *testing.T) { ptmx, success := prepare(t) - err := ptmx.SetDeadline(time.Now().Add(timeout / 10)) - if err != nil { - if errors.Is(err, os.ErrNoDeadline) { - t.Skipf("deadline is not supported on %s/%s", runtime.GOOS, runtime.GOARCH) - } else { - t.Fatalf("error: set deadline: %v\n", err) + if ptmxd, ok := ptmx.(DeadlineHolder); ok { + err := ptmxd.SetDeadline(time.Now().Add(timeout / 10)) + if err != nil { + if errors.Is(err, os.ErrNoDeadline) { + t.Skipf("deadline is not supported on %s/%s", runtime.GOOS, runtime.GOARCH) + } else { + t.Fatalf("error: set deadline: %v\n", err) + } } }