Skip to content

Commit

Permalink
Merge pull request #1083 from libp2p/web3-bot/sync
Browse files Browse the repository at this point in the history
sync: update CI config files (and fix tests)
  • Loading branch information
Stebalien authored Apr 30, 2021
2 parents 6391bff + a6747e5 commit 4ca9ecd
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 73 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass.
# This reduces the friction associated with updating with our workflows.

on: [ pull_request ]

jobs:
automerge:
if: github.event.pull_request.user.login == 'web3-bot'
runs-on: ubuntu-latest
steps:
- name: Wait on tests
uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2
with:
ref: ${{ github.event.pull_request.head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
running-workflow-name: 'automerge' # the name of this job
- name: Merge PR
uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: ""
MERGE_METHOD: "squash"
MERGE_DELETE_BRANCH: true
41 changes: 41 additions & 0 deletions .github/workflows/go-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

on: [push, pull_request]

jobs:
unit:
runs-on: ubuntu-latest
name: Go checks
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.16.x"
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@be534f007836a777104a15f2456cd1fffd3ddee8 # v2020.2.2
- name: Check that go.mod is tidy
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: gofmt
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: go vet
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: go vet ./...
- name: staticcheck
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: |
set -o pipefail
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
38 changes: 38 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

on: [push, pull_request]

jobs:
unit:
strategy:
fail-fast: false
matrix:
os: [ "ubuntu", "windows", "macos" ]
go: [ "1.15.x", "1.16.x" ]
runs-on: ${{ matrix.os }}-latest
name: Unit tests (${{ matrix.os}}, Go ${{ matrix.go }})
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Go information
run: |
go version
go env
- name: Run tests
run: go test -v -coverprofile coverage.txt ./...
- name: Run tests (32 bit)
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
env:
GOARCH: 386
run: go test -v ./...
- name: Run tests with race detector
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
run: go test -v -race ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@967e2b38a85a62bd61be5529ada27ebc109948c2 # v1.4.1
with:
file: coverage.txt
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions config/muxer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func TestCatchDuplicateTransportsMuxer(t *testing.T) {
}{
"no duplicate transports": {
h: h,
transports: []MsMuxC{MsMuxC{yamuxMuxer, "yamux"}},
transports: []MsMuxC{{yamuxMuxer, "yamux"}},
expectedError: "",
},
"duplicate transports": {
h: h,
transports: []MsMuxC{
MsMuxC{yamuxMuxer, "yamux"},
MsMuxC{yamuxMuxer, "yamux"},
{yamuxMuxer, "yamux"},
{yamuxMuxer, "yamux"},
},
expectedError: "duplicate muxer transport: yamux",
},
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/libp2p/go-libp2p

go 1.12
go 1.15

require (
github.com/btcsuite/btcd v0.21.0-beta // indirect
Expand All @@ -25,7 +25,7 @@ require (
github.com/libp2p/go-libp2p-nat v0.0.6
github.com/libp2p/go-libp2p-netutil v0.1.0
github.com/libp2p/go-libp2p-noise v0.1.3
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/libp2p/go-libp2p-peerstore v0.2.7
github.com/libp2p/go-libp2p-swarm v0.5.0
github.com/libp2p/go-libp2p-testing v0.4.0
github.com/libp2p/go-libp2p-tls v0.1.3
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ github.com/libp2p/go-libp2p-peerstore v0.1.3/go.mod h1:BJ9sHlm59/80oSkpWgr1MyY1c
github.com/libp2p/go-libp2p-peerstore v0.2.0/go.mod h1:N2l3eVIeAitSg3Pi2ipSrJYnqhVnMNQZo9nkSCuAbnQ=
github.com/libp2p/go-libp2p-peerstore v0.2.1/go.mod h1:NQxhNjWxf1d4w6PihR8btWIRjwRLBr4TYKfNgrUkOPA=
github.com/libp2p/go-libp2p-peerstore v0.2.2/go.mod h1:NQxhNjWxf1d4w6PihR8btWIRjwRLBr4TYKfNgrUkOPA=
github.com/libp2p/go-libp2p-peerstore v0.2.6 h1:2ACefBX23iMdJU9Ke+dcXt3w86MIryes9v7In4+Qq3U=
github.com/libp2p/go-libp2p-peerstore v0.2.6/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuDHItOpf2W8RxAi50P2s=
github.com/libp2p/go-libp2p-peerstore v0.2.7 h1:83JoLxyR9OYTnNfB5vvFqvMUv/xDNa6NoPHnENhBsGw=
github.com/libp2p/go-libp2p-peerstore v0.2.7/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuDHItOpf2W8RxAi50P2s=
github.com/libp2p/go-libp2p-pnet v0.2.0 h1:J6htxttBipJujEjz1y0a5+eYoiPcFHhSYHH6na5f0/k=
github.com/libp2p/go-libp2p-pnet v0.2.0/go.mod h1:Qqvq6JH/oMZGwqs3N1Fqhv8NVhrdYcO0BW4wssv21LA=
github.com/libp2p/go-libp2p-quic-transport v0.10.0 h1:koDCbWD9CCHwcHZL3/WEvP2A+e/o5/W5L3QS/2SPMA0=
Expand Down
41 changes: 24 additions & 17 deletions p2p/host/basic/basic_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ func TestHostAddrsFactory(t *testing.T) {
t.Fatalf("expected %s, got %s", maddr.String(), addrs[0].String())
}

var err error
h.autoNat, err = autonat.New(ctx, h, autonat.WithReachability(network.ReachabilityPublic))
autoNat, err := autonat.New(ctx, h, autonat.WithReachability(network.ReachabilityPublic))
if err != nil {
t.Fatalf("should be able to attach autonat: %v", err)
}
h.SetAutoNat(autoNat)
addrs = h.Addrs()
if len(addrs) != 1 {
t.Fatalf("didn't expect change in returned addresses.")
Expand Down Expand Up @@ -283,7 +283,7 @@ func assertWait(t *testing.T, c chan protocol.ID, exp protocol.ID) {
select {
case proto := <-c:
if proto != exp {
t.Fatal("should have connected on ", exp)
t.Fatalf("should have connected on %s, got %s", exp, proto)
}
case <-time.After(time.Second * 5):
t.Fatal("timeout waiting for stream")
Expand All @@ -309,6 +309,10 @@ func TestHostProtoPreference(t *testing.T) {
s.Close()
}

// Prevent pushing identify information so this test works.
h2.RemoveStreamHandler(identify.IDPush)
h2.RemoveStreamHandler(identify.IDDelta)

h1.SetStreamHandler(protoOld, handler)

s, err := h2.NewStream(ctx, h1.ID(), protoMinor, protoNew, protoOld)
Expand Down Expand Up @@ -344,8 +348,6 @@ func TestHostProtoPreference(t *testing.T) {
t.Fatal(err)
}

// XXX: This is racy now that we push protocol updates. If this tests
// fails, try allowing both protoOld and protoMinor.
assertWait(t, connectedOn, protoOld)

s2.Close()
Expand Down Expand Up @@ -399,6 +401,10 @@ func TestHostProtoPreknowledge(t *testing.T) {

h1.SetStreamHandler("/super", handler)

// Prevent pushing identify information so this test actually _uses_ the super protocol.
h2.RemoveStreamHandler(identify.IDPush)
h2.RemoveStreamHandler(identify.IDDelta)

h2pi := h2.Peerstore().PeerInfo(h2.ID())
if err := h1.Connect(ctx, h2pi); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -507,7 +513,7 @@ func TestProtoDowngrade(t *testing.T) {
}
s.Close()

h1.Network().ConnsToPeer(h2.ID())[0].Close()
h1.Network().ClosePeer(h2.ID())

time.Sleep(time.Millisecond * 50) // allow notifications to propagate
h1.RemoveStreamHandler("/testing/1.0.0")
Expand All @@ -526,16 +532,16 @@ func TestProtoDowngrade(t *testing.T) {
t.Fatal(err)
}

if s2.Protocol() != "/testing" {
t.Fatal("shoould have gotten /testing")
}

_, err = s2.Write(nil)
if err != nil {
t.Fatal(err)
}

assertWait(t, connectedOn, "/testing")

if s2.Protocol() != "/testing" {
t.Fatal("shoould have gotten /testing")
}
s2.Close()

}
Expand All @@ -558,7 +564,7 @@ func TestAddrResolution(t *testing.T) {
p2paddr3 := ma.StringCast("/ip4/192.0.2.1/tcp/123/p2p/" + p2.Pretty())

backend := &madns.MockResolver{
TXT: map[string][]string{"_dnsaddr.example.com": []string{
TXT: map[string][]string{"_dnsaddr.example.com": {
"dnsaddr=" + p2paddr2.String(), "dnsaddr=" + p2paddr3.String(),
}},
}
Expand Down Expand Up @@ -607,14 +613,14 @@ func TestAddrResolutionRecursive(t *testing.T) {

backend := &madns.MockResolver{
TXT: map[string][]string{
"_dnsaddr.example.com": []string{
"_dnsaddr.example.com": {
"dnsaddr=" + p2paddr1i.String(),
"dnsaddr=" + p2paddr2i.String(),
},
"_dnsaddr.foo.example.com": []string{
"_dnsaddr.foo.example.com": {
"dnsaddr=" + p2paddr1f.String(),
},
"_dnsaddr.bar.example.com": []string{
"_dnsaddr.bar.example.com": {
"dnsaddr=" + p2paddr2i.String(),
},
},
Expand Down Expand Up @@ -657,18 +663,19 @@ func TestAddrChangeImmediatelyIfAddressNonEmpty(t *testing.T) {
ctx := context.Background()
taddrs := []ma.Multiaddr{ma.StringCast("/ip4/1.2.3.4/tcp/1234")}

starting := make(chan struct{})
h := New(swarmt.GenSwarm(t, ctx), AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
<-starting
return taddrs
}))
defer h.Close()

sub, err := h.EventBus().Subscribe(&event.EvtLocalAddressesUpdated{})
close(starting)
if err != nil {
t.Error(err)
}
defer sub.Close()
// wait for the host background thread to start
time.Sleep(1 * time.Second)

expected := event.EvtLocalAddressesUpdated{
Diffs: true,
Expand Down Expand Up @@ -837,7 +844,7 @@ func waitForAddrChangeEvent(ctx context.Context, sub event.Subscription, t *test
return evt.(event.EvtLocalAddressesUpdated)
case <-ctx.Done():
t.Fatal("context should not have cancelled")
case <-time.After(2 * time.Second):
case <-time.After(5 * time.Second):
t.Fatal("timed out waiting for address change event")
}
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/basic/natmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func (nmgr *natManager) sync() {
// new mappings.
func (nmgr *natManager) doSync() {
ports := map[string]map[int]bool{
"tcp": map[int]bool{},
"udp": map[int]bool{},
"tcp": {},
"udp": {},
}
for _, maddr := range nmgr.net.ListenAddresses() {
// Strip the IP
Expand Down
11 changes: 8 additions & 3 deletions p2p/net/mock/mock_notif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,15 @@ func TestNotifications(t *testing.T) {
}

for _, n1 := range notifiees {
// Avoid holding this lock while waiting, otherwise we can deadlock.
streamStateCopy := map[network.Stream]chan struct{}{}
n1.streamState.Lock()
for str1, ch1 := range n1.streamState.m {
for str, ch := range n1.streamState.m {
streamStateCopy[str] = ch
}
n1.streamState.Unlock()

for str1, ch1 := range streamStateCopy {
<-ch1
str2 := StreamComplement(str1)
n2 := notifiees[str1.Conn().RemotePeer()]
Expand All @@ -151,8 +158,6 @@ func TestNotifications(t *testing.T) {

<-ch2
}

n1.streamState.Unlock()
}
}

Expand Down
Loading

0 comments on commit 4ca9ecd

Please sign in to comment.