Skip to content

Commit

Permalink
Merge pull request #180 from WeidiDeng/non-blocking
Browse files Browse the repository at this point in the history
Add non-blocking notes
  • Loading branch information
creack authored Dec 9, 2023
2 parents 3194d69 + f3f519e commit 03db72c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
# Run the tests again 100 times without verbose.
- if: ${{ matrix.go_version != '1.6.x' }}
name: Many Tests
run: go test -count=100 -timeout=10s
run: go test -count=100 -timeout=30s
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go get github.com/creack/pty

## Examples

Note that those examples are for demonstration purpose only, to showcase how to use the library. They are not meant to be used in any kind of production environment.
Note that those examples are for demonstration purpose only, to showcase how to use the library. They are not meant to be used in any kind of production environment. If you want to **set deadlines to work** and `Close()` **interrupting** `Read()` on the returned `*os.File`, you will need to call `syscall.SetNonblock` manually.

### Command

Expand Down
11 changes: 7 additions & 4 deletions io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"runtime"
"sync"
"syscall"
"testing"
"time"
)
Expand All @@ -28,9 +29,10 @@ var glTestFdLock sync.Mutex
//
//nolint:paralleltest // Potential in (*os.File).Fd().
func TestReadDeadline(t *testing.T) {
t.Skip("Disabling while investigating race.")

ptmx, success := prepare(t)
if err := syscall.SetNonblock(int(ptmx.Fd()), true); err != nil {
t.Fatalf("Error: set non block: %s", err)
}

if err := ptmx.SetDeadline(time.Now().Add(timeout / 10)); err != nil {
if errors.Is(err, os.ErrNoDeadline) {
Expand Down Expand Up @@ -59,9 +61,10 @@ func TestReadDeadline(t *testing.T) {
//
//nolint:paralleltest // Potential in (*os.File).Fd().
func TestReadClose(t *testing.T) {
t.Skip("Disabling while investigating race.")

ptmx, success := prepare(t)
if err := syscall.SetNonblock(int(ptmx.Fd()), true); err != nil {
t.Fatalf("Error: set non block: %s", err)
}

go func() {
time.Sleep(timeout / 10)
Expand Down

0 comments on commit 03db72c

Please sign in to comment.