diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 25e1afd..251f7fa 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -11,12 +11,12 @@ jobs: env: RUNGOGENERATE: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: - go-version: "1.18.x" + go-version: "1.19.x" - name: Run repo-specific setup uses: ./.github/actions/go-check-setup if: hashFiles('./.github/actions/go-check-setup') != '' @@ -27,7 +27,7 @@ jobs: echo "RUNGOGENERATE=true" >> $GITHUB_ENV fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0) + run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index b86241a..8a1697b 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,16 +10,16 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.17.x", "1.18.x" ] + go: [ "1.18.x", "1.19.x" ] env: COVERAGES: "" runs-on: ${{ format('{0}-latest', matrix.os) }} name: ${{ matrix.os }} (go ${{ matrix.go }}) steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - name: Go information @@ -43,7 +43,7 @@ jobs: # Use -coverpkg=./..., so that we include cross-package coverage. # If package ./A imports ./B, and ./A's tests also cover ./B, # this means ./B's coverage will be significantly higher than 0%. - run: go test -v -coverprofile=module-coverage.txt -coverpkg=./... ./... + run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. uses: protocol/multiple-go-modules@v1.2 @@ -52,7 +52,7 @@ jobs: with: run: | export "PATH=${{ env.PATH_386 }}:$PATH" - go test -v ./... + go test -v -shuffle=on ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow uses: protocol/multiple-go-modules@v1.2 @@ -62,7 +62,7 @@ jobs: shell: bash run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} diff --git a/go.mod b/go.mod index 172fced..a68a546 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/libp2p/go-yamux/v3 -go 1.17 +go 1.18 require ( github.com/libp2p/go-buffer-pool v0.0.2 diff --git a/session.go b/session.go index 38adcd6..ac9b5ef 100644 --- a/session.go +++ b/session.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "log" "math" "net" @@ -692,7 +691,7 @@ func (s *Session) handleStreamMessage(hdr header) error { // Drain any data on the wire if hdr.MsgType() == typeData && hdr.Length() > 0 { s.logger.Printf("[WARN] yamux: Discarding data for stream: %d", id) - if _, err := io.CopyN(ioutil.Discard, s.reader, int64(hdr.Length())); err != nil { + if _, err := io.CopyN(io.Discard, s.reader, int64(hdr.Length())); err != nil { s.logger.Printf("[ERR] yamux: Failed to discard data: %v", err) return nil } diff --git a/session_norace_test.go b/session_norace_test.go index f8dae2a..87c4d92 100644 --- a/session_norace_test.go +++ b/session_norace_test.go @@ -1,5 +1,4 @@ //go:build !race -// +build !race package yamux @@ -7,7 +6,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "sync" "testing" "time" @@ -81,7 +79,7 @@ func TestSendData_VeryLarge(t *testing.T) { return } - recv, err := io.Copy(ioutil.Discard, stream) + recv, err := io.Copy(io.Discard, stream) if err != nil { t.Errorf("err: %v", err) return diff --git a/session_test.go b/session_test.go index f327804..91cb7a8 100644 --- a/session_test.go +++ b/session_test.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "math/rand" "net" "reflect" @@ -629,7 +628,7 @@ func TestSendData_Large(t *testing.T) { func TestGoAway(t *testing.T) { // This test is noisy. conf := testConf() - conf.LogOutput = ioutil.Discard + conf.LogOutput = io.Discard client, server := testClientServerConfig(conf) defer client.Close() @@ -1352,7 +1351,7 @@ func TestWindowOverflow(t *testing.T) { msg := make([]byte, client.config.MaxStreamWindowSize*2) hdr2 := encode(typeData, 0, i, uint32(len(msg))) _ = client.sendMsg(hdr2, msg, nil) - _, err = ioutil.ReadAll(s) + _, err = io.ReadAll(s) if err == nil { t.Fatal("expected to read no data") } @@ -1483,7 +1482,7 @@ func TestStreamHalfClose2(t *testing.T) { stream.CloseWrite() wait <- struct{}{} - buf, err := ioutil.ReadAll(stream) + buf, err := io.ReadAll(stream) if err != nil { t.Error(err) } @@ -1507,7 +1506,7 @@ func TestStreamResetRead(t *testing.T) { t.Error(err) } - _, err = ioutil.ReadAll(stream) + _, err = io.ReadAll(stream) if err == nil { t.Errorf("expected reset") } @@ -1521,7 +1520,7 @@ func TestStreamResetRead(t *testing.T) { go func() { defer wc.Done() - _, err := ioutil.ReadAll(stream) + _, err := io.ReadAll(stream) if err == nil { t.Errorf("expected reset") } @@ -1572,7 +1571,7 @@ func TestLotsOfWritesWithStreamDeadline(t *testing.T) { t.Error(err) return } - if b, err := ioutil.ReadAll(stream2); len(b) != 0 || err != ErrTimeout { + if b, err := io.ReadAll(stream2); len(b) != 0 || err != ErrTimeout { t.Errorf("writes from the client should've expired; got: %v, bytes: %v", err, b) return } @@ -1723,7 +1722,7 @@ func TestInitialStreamWindow(t *testing.T) { if err != nil { t.Fatal(err) } - data, err := ioutil.ReadAll(str) + data, err := io.ReadAll(str) if err != nil { t.Fatal(err) } diff --git a/util.go b/util.go index aeccd24..62bf0d1 100644 --- a/util.go +++ b/util.go @@ -40,30 +40,28 @@ func min(values ...uint32) uint32 { // The segmented buffer looks like: // -// | data | empty space | -// < window (10) > -// < len (5) > < cap (5) > +// | data | empty space | +// < window (10) > +// < len (5) > < cap (5) > // // As data is read, the buffer gets updated like so: // -// | data | empty space | -// < window (8) > -// < len (3) > < cap (5) > +// | data | empty space | +// < window (8) > +// < len (3) > < cap (5) > // // It can then grow as follows (given a "max" of 10): // -// -// | data | empty space | -// < window (10) > -// < len (3) > < cap (7) > +// | data | empty space | +// < window (10) > +// < len (3) > < cap (7) > // // Data can then be written into the empty space, expanding len, // and shrinking cap: // -// | data | empty space | -// < window (10) > -// < len (5) > < cap (5) > -// +// | data | empty space | +// < window (10) > +// < len (5) > < cap (5) > type segmentedBuffer struct { cap uint32 len uint32 diff --git a/util_test.go b/util_test.go index 90b9cbe..488835b 100644 --- a/util_test.go +++ b/util_test.go @@ -3,7 +3,6 @@ package yamux import ( "bytes" "io" - "io/ioutil" "testing" ) @@ -93,7 +92,7 @@ func TestSegmentedBuffer(t *testing.T) { if grew, amount := buf.GrowTo(100, false); grew || amount != 0 { t.Fatal("should not grow when data hasn't been read") } - read, err := io.CopyN(ioutil.Discard, &buf, 50) + read, err := io.CopyN(io.Discard, &buf, 50) if err != nil { t.Fatal(err) }