Skip to content

Commit 4b1747b

Browse files
authored
Add test-fast for Go unit testing (#4847)
* Add test-fast for Go unit testing Speed up local human + agent unit test loops by making a new testing target. CI is untouched so it still runs the full test suite. - Add `test-fast` to get a much faster unit test loop in Go code. This passes `-short` to go test, skips fuzzing, and omits `-race`. - Gate slow integration-style tests, stress tests, and tests relying on sleeps behind Go's testing.Short() configuration. - Add t.Parallel() to certain tests where appropriate (Go tests run in - Shortens fuzz time for a specific test since it hasn't had any issues since merged
1 parent 0802921 commit 4b1747b

14 files changed

Lines changed: 207 additions & 21 deletions

File tree

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ test-coverage:
5959
@set -o pipefail && (cd node && go test -count=1 -v -timeout 5m -race -cover ./...) 2>&1 | tee coverage.txt
6060
@set -o pipefail && (cd sdk && go test -count=1 -v -timeout 5m -race -cover ./...) 2>&1 | tee -a coverage.txt
6161

62+
.PHONY: test-fast
63+
## Run fast tests for node and sdk, skipping tests gated by testing.Short() and fuzz smoke tests
64+
test-fast:
65+
@echo "Running fast tests for node and sdk..."
66+
@cd node && go test -short ./...
67+
@cd sdk && go test -short ./...
68+
6269
.PHONY: check-coverage
6370
## Check coverage against baseline (run tests first)
6471
check-coverage: build-coverage-check test-coverage

node/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
.PHONY: lint
2-
lint:
2+
lint:
33
golangci-lint run -c ../.golangci.yml ./...
44

55
.PHONY: test
66
test:
77
go test -v ./...
8-
timeout 10s go test -fuzz=FuzzMessagePublicationUnmarshalBinary -fuzztime=5s ./pkg/common || true
8+
timeout 5s go test -fuzz=FuzzMessagePublicationUnmarshalBinary -fuzztime=3s ./pkg/common || true
9+
10+
.PHONY: test-fast
11+
test-fast:
12+
go test -short ./...
913

1014
.PHONY: test-coverage
1115
test-coverage:

node/pkg/db/accountant_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
)
2424

2525
func TestAcctPendingTransferMsgID(t *testing.T) {
26+
t.Parallel()
27+
2628
tokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
2729
require.NoError(t, err)
2830

@@ -42,6 +44,8 @@ func TestAcctPendingTransferMsgID(t *testing.T) {
4244
}
4345

4446
func TestAcctIsPendingTransfer(t *testing.T) {
47+
t.Parallel()
48+
4549
assert.Equal(t, true, acctIsPendingTransfer([]byte("ACCT:PXFER3:"+"2/0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16/789101112131415")))
4650
assert.Equal(t, false, acctIsPendingTransfer([]byte("ACCT:PXFER3:")))
4751
assert.Equal(t, false, acctIsPendingTransfer([]byte("ACCT:PXFER3:1")))
@@ -56,6 +60,8 @@ func TestAcctIsPendingTransfer(t *testing.T) {
5660
}
5761

5862
func TestAcctStoreAndDeletePendingTransfers(t *testing.T) {
63+
t.Parallel()
64+
5965
dbPath := t.TempDir()
6066
db := OpenDb(zap.NewNop(), &dbPath)
6167
defer db.Close()
@@ -119,6 +125,8 @@ func TestAcctStoreAndDeletePendingTransfers(t *testing.T) {
119125
}
120126

121127
func TestAcctGetEmptyData(t *testing.T) {
128+
t.Parallel()
129+
122130
logger := zap.NewNop()
123131
dbPath := t.TempDir()
124132
db := OpenDb(logger, &dbPath)
@@ -130,6 +138,8 @@ func TestAcctGetEmptyData(t *testing.T) {
130138
}
131139

132140
func TestAcctGetData(t *testing.T) {
141+
t.Parallel()
142+
133143
logger := zap.NewNop()
134144
dbPath := t.TempDir()
135145
db := OpenDb(logger, &dbPath)
@@ -194,6 +204,8 @@ func TestAcctGetData(t *testing.T) {
194204
}
195205

196206
func TestAcctLoadingWhereOldPendingGetsUpdated(t *testing.T) {
207+
t.Parallel()
208+
197209
dbPath := t.TempDir()
198210
db := OpenDb(zap.NewNop(), &dbPath)
199211
defer db.Close()
@@ -325,6 +337,8 @@ func (msg *OldMessagePublication) MessageIDString() string {
325337
}
326338

327339
func TestUnmarshalOldJSON(t *testing.T) {
340+
t.Parallel()
341+
328342
jsn := `
329343
{
330344
"TxID": "SGVsbG8=",

node/pkg/db/db_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func getVAAWithSeqNum(seqNum uint64) vaa.VAA {
4747

4848
// Testing the expected default behavior of a CreateGovernanceVAA
4949
func TestVaaIDFromString(t *testing.T) {
50+
t.Parallel()
51+
5052
vaaIdString := "1/0000000000000000000000000000000000000000000000000000000000000004/1"
5153
vaaID, _ := VaaIDFromString(vaaIdString)
5254
expectAddr := vaa.Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}
@@ -57,6 +59,8 @@ func TestVaaIDFromString(t *testing.T) {
5759
}
5860

5961
func TestVaaIDFromVAA(t *testing.T) {
62+
t.Parallel()
63+
6064
testVaa := getVAA()
6165
vaaID := VaaIDFromVAA(&testVaa)
6266
expectAddr := vaa.Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}
@@ -67,6 +71,8 @@ func TestVaaIDFromVAA(t *testing.T) {
6771
}
6872

6973
func TestBytes(t *testing.T) {
74+
t.Parallel()
75+
7076
vaaIdString := "1/0000000000000000000000000000000000000000000000000000000000000004/1"
7177
vaaID, _ := VaaIDFromString(vaaIdString)
7278
expected := []byte{0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x2f, 0x31, 0x2f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x2f, 0x31}
@@ -75,6 +81,8 @@ func TestBytes(t *testing.T) {
7581
}
7682

7783
func TestEmitterPrefixBytesWithChainIDAndAddress(t *testing.T) {
84+
t.Parallel()
85+
7886
vaaIdString := "1/0000000000000000000000000000000000000000000000000000000000000004/1"
7987
vaaID, _ := VaaIDFromString(vaaIdString)
8088
expected := []byte{0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x2f, 0x31, 0x2f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34}
@@ -83,11 +91,15 @@ func TestEmitterPrefixBytesWithChainIDAndAddress(t *testing.T) {
8391
}
8492

8593
func TestEmitterPrefixBytesWithOnlyChainID(t *testing.T) {
94+
t.Parallel()
95+
8696
vaaID := VAAID{EmitterChain: vaa.ChainID(26)}
8797
assert.Equal(t, []byte("signed/26"), vaaID.EmitterPrefixBytes())
8898
}
8999

90100
func TestStoreSignedVAAUnsigned(t *testing.T) {
101+
t.Parallel()
102+
91103
dbPath := t.TempDir()
92104
db := OpenDb(zap.NewNop(), &dbPath)
93105
defer db.Close()
@@ -100,6 +112,8 @@ func TestStoreSignedVAAUnsigned(t *testing.T) {
100112
}
101113

102114
func TestStoreSignedVAASigned(t *testing.T) {
115+
t.Parallel()
116+
103117
dbPath := t.TempDir()
104118
db := OpenDb(zap.NewNop(), &dbPath)
105119
defer db.Close()
@@ -115,6 +129,12 @@ func TestStoreSignedVAASigned(t *testing.T) {
115129
}
116130

117131
func TestStoreSignedVAABatch(t *testing.T) {
132+
if testing.Short() {
133+
t.Skip("skipping large signed VAA batch stress test in short mode")
134+
}
135+
136+
t.Parallel()
137+
118138
dbPath := t.TempDir()
119139
db := OpenDb(zap.NewNop(), &dbPath)
120140
defer db.Close()
@@ -174,6 +194,8 @@ func TestStoreSignedVAABatch(t *testing.T) {
174194
}
175195

176196
func TestGetSignedVAABytes(t *testing.T) {
197+
t.Parallel()
198+
177199
dbPath := t.TempDir()
178200
db := OpenDb(zap.NewNop(), &dbPath)
179201
defer db.Close()
@@ -201,6 +223,8 @@ func TestGetSignedVAABytes(t *testing.T) {
201223
}
202224

203225
func TestFindEmitterSequenceGap(t *testing.T) {
226+
t.Parallel()
227+
204228
dbPath := t.TempDir()
205229
db := OpenDb(zap.NewNop(), &dbPath)
206230
defer db.Close()

node/pkg/db/governor_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func (d *Database) rowExistsInDB(key []byte) error {
2323
}
2424

2525
func TestSerializeAndDeserializeOfTransfer(t *testing.T) {
26+
t.Parallel()
27+
2628
tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
2729
require.NoError(t, err)
2830

@@ -58,6 +60,8 @@ func TestSerializeAndDeserializeOfTransfer(t *testing.T) {
5860
}
5961

6062
func TestPendingMsgIDV5(t *testing.T) {
63+
t.Parallel()
64+
6165
ethereumTokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
6266
require.NoError(t, err)
6367

@@ -76,6 +80,8 @@ func TestPendingMsgIDV5(t *testing.T) {
7680
}
7781

7882
func TestTransferMsgIDV5(t *testing.T) {
83+
t.Parallel()
84+
7985
tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
8086
require.NoError(t, err)
8187

@@ -103,6 +109,8 @@ func TestTransferMsgIDV5(t *testing.T) {
103109

104110
// TestTransferMsgIDV4 tests the old transfer format prefix (now superseded by V5).
105111
func TestTransferMsgIDV4(t *testing.T) {
112+
t.Parallel()
113+
106114
tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
107115
require.NoError(t, err)
108116

@@ -131,6 +139,8 @@ func TestTransferMsgIDV4(t *testing.T) {
131139
// TestIsTransferV5 tests the IsTransfer function for the current transfer format.
132140
// The V5 suffix matches the "GOV:XFER5:" prefix used by the current transfer implementation.
133141
func TestIsTransferV5(t *testing.T) {
142+
t.Parallel()
143+
134144
tests := []struct {
135145
name string
136146
input []byte
@@ -189,7 +199,10 @@ func TestIsTransferV5(t *testing.T) {
189199
}
190200

191201
for _, tt := range tests {
202+
tt := tt
192203
t.Run(tt.name, func(t *testing.T) {
204+
t.Parallel()
205+
193206
result := IsTransfer(tt.input)
194207
assert.Equal(t, tt.expected, result)
195208
})
@@ -199,6 +212,8 @@ func TestIsTransferV5(t *testing.T) {
199212
// TestIsTransferV4 tests the isOldTransfer function for the legacy transfer format.
200213
// The V4 suffix matches the "GOV:XFER4:" prefix used by the old transfer implementation.
201214
func TestIsTransferV4(t *testing.T) {
215+
t.Parallel()
216+
202217
tests := []struct {
203218
name string
204219
input []byte
@@ -252,7 +267,10 @@ func TestIsTransferV4(t *testing.T) {
252267
}
253268

254269
for _, tt := range tests {
270+
tt := tt
255271
t.Run(tt.name, func(t *testing.T) {
272+
t.Parallel()
273+
256274
result := isOldTransfer(tt.input)
257275
assert.Equal(t, tt.expected, result)
258276
})
@@ -262,6 +280,8 @@ func TestIsTransferV4(t *testing.T) {
262280
// TestIsPendingMsgV5 tests the IsPendingMsg function for the current pending message format.
263281
// The V5 suffix matches the "GOV:PENDING5:" prefix used by the current pending message implementation.
264282
func TestIsPendingMsgV5(t *testing.T) {
283+
t.Parallel()
284+
265285
tests := []struct {
266286
name string
267287
input []byte
@@ -320,7 +340,10 @@ func TestIsPendingMsgV5(t *testing.T) {
320340
}
321341

322342
for _, tt := range tests {
343+
tt := tt
323344
t.Run(tt.name, func(t *testing.T) {
345+
t.Parallel()
346+
324347
result := IsPendingMsg(tt.input)
325348
assert.Equal(t, tt.expected, result)
326349
})
@@ -330,6 +353,8 @@ func TestIsPendingMsgV5(t *testing.T) {
330353
// TestIsPendingMsgV4 tests the isOldPendingMsg function for the legacy pending message format.
331354
// The V4 suffix matches the "GOV:PENDING4:" prefix used by the legacy pending message implementation.
332355
func TestIsPendingMsgV4(t *testing.T) {
356+
t.Parallel()
357+
333358
tests := []struct {
334359
name string
335360
input []byte
@@ -383,14 +408,19 @@ func TestIsPendingMsgV4(t *testing.T) {
383408
}
384409

385410
for _, tt := range tests {
411+
tt := tt
386412
t.Run(tt.name, func(t *testing.T) {
413+
t.Parallel()
414+
387415
result := isOldPendingMsg(tt.input)
388416
assert.Equal(t, tt.expected, result)
389417
})
390418
}
391419
}
392420

393421
func TestGetChainGovernorData(t *testing.T) {
422+
t.Parallel()
423+
394424
dbPath := t.TempDir()
395425
db := OpenDb(zap.NewNop(), &dbPath)
396426
defer db.Close()
@@ -405,6 +435,8 @@ func TestGetChainGovernorData(t *testing.T) {
405435
}
406436

407437
func TestStoreTransfer(t *testing.T) {
438+
t.Parallel()
439+
408440
dbPath := t.TempDir()
409441
db := OpenDb(zap.NewNop(), &dbPath)
410442
defer db.Close()
@@ -436,6 +468,8 @@ func TestStoreTransfer(t *testing.T) {
436468
}
437469

438470
func TestDeleteTransfer(t *testing.T) {
471+
t.Parallel()
472+
439473
dbPath := t.TempDir()
440474
db := OpenDb(zap.NewNop(), &dbPath)
441475
defer db.Close()
@@ -476,6 +510,8 @@ func TestDeleteTransfer(t *testing.T) {
476510
}
477511

478512
func TestStorePendingMsg(t *testing.T) {
513+
t.Parallel()
514+
479515
dbPath := t.TempDir()
480516
db := OpenDb(zap.NewNop(), &dbPath)
481517
defer db.Close()
@@ -501,6 +537,8 @@ func TestStorePendingMsg(t *testing.T) {
501537
}
502538

503539
func TestDeletePendingMsg(t *testing.T) {
540+
t.Parallel()
541+
504542
dbPath := t.TempDir()
505543
db := OpenDb(zap.NewNop(), &dbPath)
506544
defer db.Close()
@@ -535,6 +573,8 @@ func TestDeletePendingMsg(t *testing.T) {
535573
}
536574

537575
func TestSerializeAndDeserializeOfPendingTransfer(t *testing.T) {
576+
t.Parallel()
577+
538578
tokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
539579
require.NoError(t, err)
540580

@@ -570,6 +610,8 @@ func TestSerializeAndDeserializeOfPendingTransfer(t *testing.T) {
570610
}
571611

572612
func TestStoreAndReloadTransfersAndPendingMessages(t *testing.T) {
613+
t.Parallel()
614+
573615
dbPath := t.TempDir()
574616
db := OpenDb(zap.NewNop(), &dbPath)
575617
defer db.Close()
@@ -664,6 +706,8 @@ func TestStoreAndReloadTransfersAndPendingMessages(t *testing.T) {
664706
}
665707

666708
func TestMarshalUnmarshalNoMsgIdOrHash(t *testing.T) {
709+
t.Parallel()
710+
667711
tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
668712
require.NoError(t, err)
669713

@@ -696,6 +740,8 @@ func TestMarshalUnmarshalNoMsgIdOrHash(t *testing.T) {
696740
// Note that Transfer.Marshal can't fail, so there are no negative tests for that.
697741

698742
func TestUnmarshalTransferFailures(t *testing.T) {
743+
t.Parallel()
744+
699745
tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
700746
require.NoError(t, err)
701747

@@ -778,6 +824,8 @@ func TestUnmarshalTransferFailures(t *testing.T) {
778824
// Note that PendingTransfer.Marshal can't fail, so there are no negative tests for that.
779825

780826
func TestUnmarshalPendingTransferFailures(t *testing.T) {
827+
t.Parallel()
828+
781829
tokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
782830
require.NoError(t, err)
783831

0 commit comments

Comments
 (0)