1
1
import pytest
2
2
from plenum .common .config_helper import PNodeConfigHelper
3
+ from plenum .common .messages .node_messages import LedgerStatus , ConsistencyProof
3
4
from plenum .common .util import getCallableName
5
+ from plenum .server .router import Route
4
6
from plenum .test .helper import sdk_send_random_and_check
5
7
from plenum .test .node_catchup .helper import waitNodeDataEquality
6
8
from plenum .test .pool_transactions .helper import \
12
14
call_count = 0
13
15
14
16
15
- @pytest .fixture (scope = 'function' , params = range (1 , 4 ))
17
+ @pytest .fixture (scope = 'function' , params = range (1 , 5 ))
16
18
def lost_count (request ):
17
19
return request .param
18
20
@@ -31,14 +33,6 @@ def test_catchup_with_lost_ledger_status(txnPoolNodeSet,
31
33
32
34
node_to_disconnect = txnPoolNodeSet [- 1 ]
33
35
34
- def unpatch_after_call (status , frm ):
35
- global call_count
36
- call_count += 1
37
- if call_count >= lost_count :
38
- # unpatch processLedgerStatus after lost_count calls
39
- monkeypatch .undo ()
40
- call_count = 0
41
-
42
36
sdk_send_random_and_check (looper , txnPoolNodeSet ,
43
37
sdk_pool_handle , sdk_wallet_steward , 5 )
44
38
@@ -60,9 +54,17 @@ def unpatch_after_call(status, frm):
60
54
config = tconf ,
61
55
ha = nodeHa , cliha = nodeCHa ,
62
56
pluginPaths = allPluginsPath )
57
+
58
+ def unpatch_after_call (status , frm ):
59
+ global call_count
60
+ call_count += 1
61
+ if call_count >= lost_count :
62
+ # unpatch processLedgerStatus after lost_count calls
63
+ node_to_disconnect .nodeMsgRouter .add ((LedgerStatus , node_to_disconnect .ledgerManager .processLedgerStatus ))
64
+ call_count = 0
65
+
63
66
# patch processLedgerStatus
64
- monkeypatch .setattr (node_to_disconnect .ledgerManager , 'processLedgerStatus' ,
65
- unpatch_after_call )
67
+ node_to_disconnect .nodeMsgRouter .add ((LedgerStatus , unpatch_after_call ))
66
68
67
69
# add node_to_disconnect to pool
68
70
looper .add (node_to_disconnect )
@@ -88,14 +90,6 @@ def test_catchup_with_lost_first_consistency_proofs(txnPoolNodeSet,
88
90
Test makes sure that the node eventually finishes catchup'''
89
91
node_to_disconnect = txnPoolNodeSet [- 1 ]
90
92
91
- def unpatch_after_call (proof , frm ):
92
- global call_count
93
- call_count += 1
94
- if call_count >= lost_count :
95
- # unpatch processConsistencyProof after lost_count calls
96
- monkeypatch .undo ()
97
- call_count = 0
98
-
99
93
sdk_send_random_and_check (looper , txnPoolNodeSet ,
100
94
sdk_pool_handle , sdk_wallet_steward , 5 )
101
95
@@ -117,10 +111,18 @@ def unpatch_after_call(proof, frm):
117
111
config = tconf ,
118
112
ha = nodeHa , cliha = nodeCHa ,
119
113
pluginPaths = allPluginsPath )
114
+
115
+ def unpatch_after_call (proof , frm ):
116
+ global call_count
117
+ call_count += 1
118
+ if call_count >= lost_count :
119
+ # unpatch processConsistencyProof after lost_count calls
120
+ node_to_disconnect .nodeMsgRouter .add ((ConsistencyProof ,
121
+ node_to_disconnect .ledgerManager .processConsistencyProof ))
122
+ call_count = 0
123
+
120
124
# patch processConsistencyProof
121
- monkeypatch .setattr (node_to_disconnect .ledgerManager ,
122
- 'processConsistencyProof' ,
123
- unpatch_after_call )
125
+ node_to_disconnect .nodeMsgRouter .add ((ConsistencyProof , unpatch_after_call ))
124
126
# add node_to_disconnect to pool
125
127
looper .add (node_to_disconnect )
126
128
txnPoolNodeSet [- 1 ] = node_to_disconnect
0 commit comments