Skip to content

Commit 1966c38

Browse files
authored
Merge pull request #2536 from kcalvinalvin/2026-05-30-run-and-fix-broken-integration-tests-1
.github: actually run the integration tests in the CI
2 parents b3cbf4f + f8ce7a7 commit 1966c38

7 files changed

Lines changed: 51 additions & 7 deletions

File tree

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,18 @@ jobs:
145145

146146
- name: Test
147147
run: make unit-race
148+
149+
test-rpctest:
150+
name: Unit rpctest
151+
runs-on: ubuntu-latest
152+
steps:
153+
- name: Set up Go
154+
uses: actions/setup-go@v5
155+
with:
156+
go-version: ${{ env.GO_VERSION }}
157+
158+
- name: Check out source
159+
uses: actions/checkout@v4
160+
161+
- name: Test
162+
run: make unit

btcjson/chainsvrresults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ func (h *StringOrArray) UnmarshalJSON(data []byte) error {
385385
}
386386

387387
switch v := unmarshalled.(type) {
388+
case nil:
389+
*h = nil
390+
388391
case string:
389392
*h = []string{v}
390393

btcjson/chainsvrresults_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,16 @@ func TestGetBlockChainInfoWarnings(t *testing.T) {
350350
result: `{"warnings": []}`,
351351
expected: btcjson.StringOrArray{},
352352
},
353+
{
354+
name: "blockchain info with null warnings",
355+
result: `{"warnings": null}`,
356+
expected: nil,
357+
},
358+
{
359+
name: "blockchain info with warnings field omitted",
360+
result: `{}`,
361+
expected: nil,
362+
},
353363
}
354364

355365
for _, test := range tests {

integration/p2a_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package integration
66
import (
77
"testing"
88

9+
"github.com/btcsuite/btcd/address/v2"
910
"github.com/btcsuite/btcd/btcutil/v2"
1011
"github.com/btcsuite/btcd/chaincfg/v2"
1112
"github.com/btcsuite/btcd/integration/rpctest"
@@ -46,7 +47,7 @@ func TestPayToAnchorSimple(t *testing.T) {
4647

4748
// Create a P2A output using the helper to get a P2A address. This
4849
// ensures we're using the same P2A script generation logic.
49-
p2aAddr, err := btcutil.NewAddressPayToAnchor(&chaincfg.SimNetParams)
50+
p2aAddr, err := address.NewAddressPayToAnchor(&chaincfg.SimNetParams)
5051
if err != nil {
5152
t.Fatalf("unable to create P2A address: %v", err)
5253
}

integration/rpctest/btcd.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package rpctest
66

77
import (
88
"fmt"
9+
"math/rand/v2"
910
"os/exec"
1011
"path/filepath"
1112
"runtime"
@@ -43,8 +44,12 @@ func btcdExecutablePath() (string, error) {
4344
return "", err
4445
}
4546

46-
// Build btcd and output an executable in a static temp path.
47-
outputPath := filepath.Join(testDir, "btcd")
47+
// Build btcd to a random path so concurrent `go test` processes
48+
// (e.g. when test packages run in parallel under `make unit`) do
49+
// not race on the same output file. Each test process pays a
50+
// one-time compile cost; within a process the compileMtx-guarded
51+
// cache keeps it to one build.
52+
outputPath := filepath.Join(testDir, fmt.Sprintf("btcd-%d", rand.Uint32()))
4853
if runtime.GOOS == "windows" {
4954
outputPath += ".exe"
5055
}

integration/rpctest/rpc_harness.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package rpctest
66

77
import (
88
"fmt"
9+
"math/rand/v2"
910
"net"
1011
"os"
1112
"path/filepath"
@@ -76,7 +77,15 @@ var (
7677

7778
// lastPort is the last port determined to be free for use by a new
7879
// node. It should be used atomically.
79-
lastPort uint32 = defaultNodePort
80+
//
81+
// Seed with a random offset so concurrent `go test` processes
82+
// (e.g. when integration/ and integration/rpctest/ run in parallel
83+
// under `make unit`) do not race on the same port range. The
84+
// bind-test in NextAvailablePort closes the listener before
85+
// returning, leaving a window where another process could grab the
86+
// same port; staggering each process's starting point avoids the
87+
// collision. The 50k-port window leaves headroom below 65535.
88+
lastPort uint32 = defaultNodePort + rand.Uint32N(50000)
8089
)
8190

8291
// HarnessTestCase represents a test-case which utilizes an instance of the

netsync/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,10 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
11241124
peer.UpdateLastAnnouncedBlock(&invVects[lastBlock].Hash)
11251125
}
11261126

1127-
// Ignore invs from peers that aren't the sync if we are not current.
1128-
// Helps prevent fetching a mass of orphans.
1129-
if peer != sm.syncPeer && !sm.current() {
1127+
// Ignore invs from peers that aren't the sync peer if we are not
1128+
// current. Helps prevent fetching a mass of orphans. When syncPeer
1129+
// is nil, accept invs from any peer.
1130+
if sm.syncPeer != nil && peer != sm.syncPeer && !sm.current() {
11301131
return
11311132
}
11321133

0 commit comments

Comments
 (0)