Skip to content

Commit 640cd7d

Browse files
Block validation stress test on high memory usage, update nightly workflow with ready test folder (#233)
1 parent 95034ac commit 640cd7d

File tree

5 files changed

+784
-136
lines changed

5 files changed

+784
-136
lines changed

.github/workflows/nightly_tests.yaml

Lines changed: 4 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env:
88
REPO: teranode
99
SETTINGS_CONTEXT_DEFAULT: default_context
1010
GO_VERSION: '1.25.2'
11-
TEST_DIR: ./test/e2e/daemon
11+
TEST_DIR: ./test/e2e/daemon/ready
1212

1313
permissions:
1414
contents: read
@@ -33,141 +33,13 @@ jobs:
3333
go-version: ${{ env.GO_VERSION }}
3434
cache: false
3535

36-
- name: Run Block Subsidy Tests
36+
- name: Run Daemon Ready Tests
3737
run: |
3838
go clean -testcache
39-
go test -v -run "^TestBlockSubsidy$" $TEST_DIR
39+
go test -v $TEST_DIR
4040
env:
4141
GITHUB_ACTIONS: true
42-
continue-on-error: true
43-
44-
- name: Run Legacy Tests
45-
run: |
46-
go test -v $TEST_DIR/legacy_test.go
47-
env:
48-
GITHUB_ACTIONS: true
49-
continue-on-error: true
50-
51-
- name: Run Reassign Tests
52-
run: |
53-
go test -v -run "^TestShouldAllowReassign$" $TEST_DIR
54-
env:
55-
GITHUB_ACTIONS: true
56-
continue-on-error: true
57-
58-
- name: Run Reorg Tests
59-
run: |
60-
go test -v -run "^(\
61-
TestMoveUp|\
62-
TestMoveDownMoveUpWhenNewBlockIsGenerated|\
63-
TestMoveDownMoveUpWhenNoNewBlockIsGenerated|\
64-
TestTDRestart|\
65-
TestDynamicSubtreeSize|\
66-
TestInvalidBlockTestBlockValidationCatchup\
67-
)$" $TEST_DIR
68-
env:
69-
GITHUB_ACTIONS: true
70-
continue-on-error: true
71-
72-
- name: Run RPC Smoke PG Tests
73-
run: |
74-
go test -v -run "^(\
75-
TestTracing|\
76-
TestSendTxAndCheckState|\
77-
TestShouldNotProcessNonFinalTx|\
78-
TestShouldRejectOversizedTx|\
79-
TestShouldRejectOversizedScript|\
80-
TestShouldAllowChainedTransactionsUseRpc|\
81-
TestDoubleInput|\
82-
TestGetBestBlockHash|\
83-
TestGetPeerInfo|\
84-
TestGetMiningInfo|\
85-
TestVersion|\
86-
TestGetBlockVerbosity|\
87-
TestGetBlockHeaderVerbose|\
88-
TestGetRawTransactionVerbose|\
89-
TestGetMiningCandidate|\
90-
TestGenerateToAddress|\
91-
TestBlockManagement\
92-
)$" $TEST_DIR
93-
env:
94-
GITHUB_ACTIONS: true
95-
continue-on-error: true
96-
97-
- name: Run Spend UTXO Tests
98-
run: |
99-
go test -v -run "^TestShouldAllowSpendAllUtxos$" $TEST_DIR
100-
env:
101-
GITHUB_ACTIONS: true
102-
continue-on-error: true
103-
104-
- name: Run UTXO Tests
105-
run: |
106-
go test -v -run "^(\
107-
TestFreezeAndUnfreezeUtxos|\
108-
TestDeleteAtHeightHappyPath|\
109-
TestSubtreeBlockHeightRetention|\
110-
)$" $TEST_DIR
111-
env:
112-
GITHUB_ACTIONS: true
113-
continue-on-error: true
114-
115-
- name: Run TNC1.1 Test
116-
run: |
117-
go test -v -run "^TestVerifyMerkleRootCalculation$" $TEST_DIR
118-
env:
119-
GITHUB_ACTIONS: true
120-
continue-on-error: true
121-
122-
- name: Run TNC1.2 Test
123-
run: |
124-
go test -v $TEST_DIR/tnc1_2_test.go
125-
env:
126-
GITHUB_ACTIONS: true
127-
continue-on-error: true
128-
129-
- name: Run TNC1.3 Test
130-
run: |
131-
go test -v $TEST_DIR/tnc1_3_test.go
132-
env:
133-
GITHUB_ACTIONS: true
134-
continue-on-error: true
135-
136-
- name: Run TNCA2 Postgres Test
137-
run: |
138-
go test -v $TEST_DIR/tna2_pg_test.go
139-
env:
140-
GITHUB_ACTIONS: true
141-
continue-on-error: true
142-
143-
- name: Run TNC2.1 Test
144-
run: |
145-
go test -v -run "^TestVerifyMerkleRootCalculation|TestConcurrentCandidateIdentifiers$" $TEST_DIR
146-
env:
147-
GITHUB_ACTIONS: true
148-
continue-on-error: true
149-
150-
- name: Run TNB2 Test
151-
run: |
152-
go test -v $TEST_DIR/tnb2_test.go
153-
env:
154-
GITHUB_ACTIONS: true
155-
continue-on-error: true
156-
157-
- name: Run TNE1.1 Test
158-
run: |
159-
go test -v $TEST_DIR/tne1_1_test.go
160-
env:
161-
GITHUB_ACTIONS: true
162-
continue-on-error: true
163-
164-
- name: Check for Test Failures
165-
if: always()
166-
run: |
167-
if [[ "${{ job.status }}" == "failure" ]]; then
168-
echo "One or more test suites failed"
169-
exit 1
170-
fi
42+
continue-on-error: false
17143

17244
chaostest:
17345
name: chaostest

.github/workflows/sonar-pr-analyze.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name: SonarQube Analysis for PRs
1313

1414
on:
1515
workflow_run:
16-
workflows: ["Teranode PR init"]
16+
workflows: ["Teranode PR tests"]
1717
types:
1818
- completed
1919

test/chaos/README.md

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ go test -v ./test/chaos/...
5656

5757
# Scenario 7: Combined Failures (DB + Kafka)
5858
./test/chaos/run_scenario_07.sh
59+
60+
# Scenario 8: Block Validation Memory Pressure
61+
./test/chaos/run_scenario_08.sh
5962
```
6063

6164
The helper scripts will:
@@ -88,6 +91,9 @@ go test -v ./test/chaos -run TestScenario06
8891

8992
# Scenario 7: Combined Failures (DB + Kafka)
9093
go test -v ./test/chaos -run TestScenario07
94+
95+
# Scenario 8: Block Validation Memory Pressure
96+
go test -v ./test/chaos -run TestScenario08
9197
```
9298

9399
### Run in Verbose Mode
@@ -525,6 +531,89 @@ go test -v ./test/chaos -run TestScenario07_StaggeredRecovery
525531

526532
**Combined scenario duration:** ~35 seconds
527533

534+
### Scenario 8: Block Validation Memory Pressure
535+
**File:** `scenario_08_block_validation_memory_test.go`
536+
537+
Tests block validation resilience under various memory pressure scenarios and subtree patterns. This validates that the block validation system can handle extreme cases without panicking or leaking resources.
538+
539+
**What it tests:**
540+
- Block validation with random subtree patterns (transient, deep chains, mixed)
541+
- Memory usage and heap allocations during validation
542+
- Goroutine lifecycle and cleanup
543+
- Cache hit rates and eviction under pressure
544+
- Concurrent validation under load
545+
- `ValidateBlockWithOptions` never panics on any generated subtree
546+
- `setTxMinedStatus` succeeds for all transactions
547+
548+
**How to run:**
549+
```bash
550+
# Using helper script
551+
./test/chaos/run_scenario_08.sh
552+
553+
# Using go test directly
554+
go test -v ./test/chaos -run TestScenario08
555+
```
556+
557+
**Test phases:**
558+
559+
1. **Baseline Metrics**
560+
- Capture initial heap allocation
561+
- Record starting goroutine count
562+
- Force GC for clean baseline
563+
564+
2. **Transient Subtrees (50 blocks)**
565+
- Generate many small blocks (shallow depth, few TXs)
566+
- Validate each subtree
567+
- Monitor heap allocation growth
568+
- Verify no goroutine leaks
569+
- Target: < 500 MB heap, < 200 goroutines
570+
571+
3. **Deep Chains (100 blocks)**
572+
- Generate deep transaction chains (up to 10 levels)
573+
- Stress caching and eviction mechanisms
574+
- Monitor cache hit/miss rates
575+
- Verify all transactions marked as mined
576+
- Expected: > 50% cache hit rate
577+
578+
4. **Mixed Patterns (30 blocks)**
579+
- Random TX depth (1-10), TX count (1-1000), TX size (100-10000 bytes)
580+
- Validate with panic recovery
581+
- Verify no panics occur under any pattern
582+
- All validations must succeed
583+
584+
5. **Concurrent Validation (10 concurrent blocks)**
585+
- Generate and validate 10 subtrees concurrently
586+
- Monitor goroutine cleanup after completion
587+
- Verify no goroutine leaks (< 5 increase after cleanup)
588+
- All concurrent validations must succeed
589+
590+
6. **Cache Eviction Under Pressure (200 blocks)**
591+
- Generate many blocks to force cache eviction
592+
- Monitor cache size changes
593+
- Verify eviction mechanism works
594+
- Expected: Multiple cache evictions observed
595+
596+
**Expected results:**
597+
- ✅ No panics under any subtree pattern
598+
- ✅ All transactions successfully marked as mined
599+
- ✅ Heap allocation stays under 500 MB
600+
- ✅ Goroutine count stays under 200
601+
- ✅ No goroutine leaks after concurrent validation
602+
- ✅ Cache hit rate > 50% for deep chains
603+
- ✅ Cache eviction works under memory pressure
604+
- ✅ All validations complete within timeout (5s per block)
605+
606+
**Performance metrics tracked:**
607+
- Heap allocations (MB)
608+
- Goroutine count
609+
- Cache hit/miss rates
610+
- Validation times (average)
611+
- Cache size and evictions
612+
613+
**Test duration:** ~45-60 seconds (depending on hardware)
614+
615+
**Note:** This test does NOT use Toxiproxy as it focuses on internal block validation logic rather than external service failures.
616+
528617
## Test Structure
529618

530619
Each chaos test follows this pattern:
@@ -698,7 +787,8 @@ Chaos tests take longer than unit tests:
698787
- Scenario 5 (Bandwidth Constraints): ~4.4 seconds (database + Kafka bandwidth tests)
699788
- Scenario 6 (Slow Close Connections): ~55 seconds (slicer toxic tests)
700789
- Scenario 7 (Combined Failures): ~35 seconds (simultaneous and staggered failures)
701-
- Full suite: ~13-14 minutes (with all scenarios)
790+
- Scenario 8 (Block Validation Memory): ~45-60 seconds (memory pressure and validation tests)
791+
- Full suite: ~14-15 minutes (with all scenarios)
702792
703793
## Troubleshooting
704794
@@ -763,8 +853,9 @@ curl -X POST http://localhost:8474/reset
763853
- [Toxiproxy GitHub](https://github.com/Shopify/toxiproxy)
764854
- [Chaos Engineering Principles](https://principlesofchaos.org/)
765855

766-
## Future Scenarios (Planned)
856+
## Implemented Scenarios
767857

858+
- [x] Scenario 1: Database Latency ✅ **Implemented**
768859
- [x] Scenario 2: Kafka Broker Failure ✅ **Implemented**
769860
- [x] Scenario 3: Network Partition ✅ **Implemented**
770861
- [x] Scenario 4A: Intermittent Connection Drops ✅ **Implemented**
@@ -773,5 +864,6 @@ curl -X POST http://localhost:8474/reset
773864
- [x] Scenario 5: Bandwidth Constraints ✅ **Implemented**
774865
- [x] Scenario 6: Slow Close Connections (Slicer toxic) ✅ **Implemented**
775866
- [x] Scenario 7: Combined Failures (DB + Kafka simultaneously) ✅ **Implemented**
867+
- [x] Scenario 8: Block Validation Memory Pressure ✅ **Implemented**
776868

777-
All planned chaos test scenarios have been implemented!
869+
All chaos test scenarios have been implemented! Total: **8 scenarios** covering network failures, infrastructure issues, and internal system resilience.

test/chaos/run_scenario_08.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Chaos Test Scenario 08: Block Validation Memory Pressure
4+
# This script runs the block validation and memory stress test
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
echo -e "${GREEN}[INFO]${NC} Starting Scenario 08: Block Validation Memory Pressure"
15+
echo -e "${GREEN}[INFO]${NC} This test validates block validation resilience under various conditions:"
16+
echo -e "${GREEN}[INFO]${NC} - Transient subtrees (many small blocks)"
17+
echo -e "${GREEN}[INFO]${NC} - Deep chains (stress caching)"
18+
echo -e "${GREEN}[INFO]${NC} - Mixed patterns (random characteristics)"
19+
echo -e "${GREEN}[INFO]${NC} - Concurrent validation"
20+
echo -e "${GREEN}[INFO]${NC} - Cache eviction under pressure"
21+
echo ""
22+
23+
echo -e "${GREEN}[INFO]${NC} =================================================="
24+
echo -e "${GREEN}[INFO]${NC} Running Scenario 8: Block Validation Memory"
25+
echo -e "${GREEN}[INFO]${NC} =================================================="
26+
echo ""
27+
28+
# Run the test with verbose output
29+
go test -v ./test/chaos -run TestScenario08
30+
31+
TEST_EXIT_CODE=$?
32+
33+
echo ""
34+
if [ $TEST_EXIT_CODE -eq 0 ]; then
35+
echo -e "${GREEN}[INFO]${NC} =================================================="
36+
echo -e "${GREEN}[INFO]${NC} ✅ Test PASSED"
37+
echo -e "${GREEN}[INFO]${NC} =================================================="
38+
else
39+
echo -e "${RED}[ERROR]${NC} =================================================="
40+
echo -e "${RED}[ERROR]${NC} ❌ Test FAILED"
41+
echo -e "${RED}[ERROR]${NC} =================================================="
42+
fi
43+
echo ""
44+
45+
exit $TEST_EXIT_CODE

0 commit comments

Comments
 (0)