-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: consolidate masternode info tracking (MasternodeInfo) in functional tests, implement helpers, add type annotations
#6718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
08d18d7
3e25b30
08e81d8
07c7319
cd7ffcf
dfca0ee
fa56126
f3777c5
89b2548
0532baf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,7 @@ def run_test(self): | |||||||
| self.log.info("checking for old intra quorum connections") | ||||||||
| total_count = 0 | ||||||||
| for mn in self.get_quorum_masternodes(q): | ||||||||
| count = self.get_mn_connection_count(mn.node) | ||||||||
| count = self.get_mn_connection_count(mn.get_node(self)) | ||||||||
| total_count += count | ||||||||
| assert_greater_than_or_equal(count, 2) | ||||||||
| assert total_count < 40 | ||||||||
|
|
@@ -49,24 +49,24 @@ def run_test(self): | |||||||
| self.log.info("mining one block and waiting for all members to connect to each other") | ||||||||
| self.generate(self.nodes[0], 1, sync_fun=self.no_op) | ||||||||
| for mn in self.get_quorum_masternodes(q): | ||||||||
| self.wait_for_mnauth(mn.node, 4) | ||||||||
| self.wait_for_mnauth(mn.get_node(self), 4) | ||||||||
|
|
||||||||
| self.log.info("mine a new quorum and verify that all members connect to each other") | ||||||||
| q = self.mine_quorum() | ||||||||
|
|
||||||||
| self.log.info("checking that all MNs got probed") | ||||||||
| for mn in self.get_quorum_masternodes(q): | ||||||||
| self.wait_until(lambda: self.get_mn_probe_count(mn.node, q, False) == 4) | ||||||||
| self.wait_until(lambda: self.get_mn_probe_count(mn.get_node(self), q, False) == 4) | ||||||||
|
|
||||||||
| self.log.info("checking that probes age") | ||||||||
| self.bump_mocktime(self.MAX_AGE) | ||||||||
| for mn in self.get_quorum_masternodes(q): | ||||||||
| self.wait_until(lambda: self.get_mn_probe_count(mn.node, q, False) == 0) | ||||||||
| self.wait_until(lambda: self.get_mn_probe_count(mn.get_node(self), q, False) == 0) | ||||||||
|
|
||||||||
| self.log.info("mine a new quorum and re-check probes") | ||||||||
| q = self.mine_quorum() | ||||||||
| for mn in self.get_quorum_masternodes(q): | ||||||||
| self.wait_until(lambda: self.get_mn_probe_count(mn.node, q, True) == 4) | ||||||||
| self.wait_until(lambda: self.get_mn_probe_count(mn.get_node(self), q, True) == 4) | ||||||||
|
|
||||||||
| self.log.info("Activating SPORK_21_QUORUM_ALL_CONNECTED") | ||||||||
| self.nodes[0].sporkupdate("SPORK_21_QUORUM_ALL_CONNECTED", 0) | ||||||||
|
|
@@ -84,12 +84,12 @@ def run_test(self): | |||||||
| self.log.info("check that old masternode connections are dropped") | ||||||||
| removed = False | ||||||||
| for mn in self.mninfo: # type: MasternodeInfo | ||||||||
| if len(mn.node.quorum("memberof", mn.proTxHash)) > 0: | ||||||||
| if len(mn.get_node(self).quorum("memberof", mn.proTxHash)) > 0: | ||||||||
| try: | ||||||||
| with mn.node.assert_debug_log(['removing masternodes quorum connections']): | ||||||||
| with mn.node.assert_debug_log(['keeping mn quorum connections']): | ||||||||
| with mn.get_node(self).assert_debug_log(['removing masternodes quorum connections']): | ||||||||
| with mn.get_node(self).assert_debug_log(['keeping mn quorum connections']): | ||||||||
| self.mine_cycle_quorum(is_first=False) | ||||||||
| mn.node.mockscheduler(60) # we check for old connections via the scheduler every 60 seconds | ||||||||
| mn.get_node(self).mockscheduler(60) # we check for old connections via the scheduler every 60 seconds | ||||||||
| removed = True | ||||||||
| except: | ||||||||
| pass # it's ok to not remove connections sometimes | ||||||||
|
|
@@ -100,9 +100,9 @@ def run_test(self): | |||||||
| self.log.info("check that inter-quorum masternode connections are added") | ||||||||
| added = False | ||||||||
| for mn in self.mninfo: # type: MasternodeInfo | ||||||||
| if len(mn.node.quorum("memberof", mn.proTxHash)) > 0: | ||||||||
| if len(mn.get_node(self).quorum("memberof", mn.proTxHash)) > 0: | ||||||||
| try: | ||||||||
| with mn.node.assert_debug_log(['adding mn inter-quorum connections']): | ||||||||
| with mn.get_node(self).assert_debug_log(['adding mn inter-quorum connections']): | ||||||||
| self.mine_cycle_quorum(is_first=False) | ||||||||
| added = True | ||||||||
| except: | ||||||||
|
|
@@ -114,17 +114,17 @@ def run_test(self): | |||||||
| def check_reconnects(self, expected_connection_count): | ||||||||
| self.log.info("disable and re-enable networking on all masternodes") | ||||||||
| for mn in self.mninfo: # type: MasternodeInfo | ||||||||
| mn.node.setnetworkactive(False) | ||||||||
| mn.get_node(self).setnetworkactive(False) | ||||||||
| for mn in self.mninfo: # type: MasternodeInfo | ||||||||
| self.wait_until(lambda: len(mn.node.getpeerinfo()) == 0) | ||||||||
| self.wait_until(lambda: len(mn.get_node(self).getpeerinfo()) == 0) | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix lambda function variable capture issue. Similar issue with lambda function capturing loop variable by reference. Apply this fix: - for mn in self.mninfo: # type: MasternodeInfo
- self.wait_until(lambda: len(mn.get_node(self).getpeerinfo()) == 0)
+ for mn in self.mninfo: # type: MasternodeInfo
+ self.wait_until(lambda mn=mn: len(mn.get_node(self).getpeerinfo()) == 0)📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.11.9)119-119: Function definition does not bind loop variable (B023) 🤖 Prompt for AI Agents |
||||||||
| for mn in self.mninfo: # type: MasternodeInfo | ||||||||
| mn.node.setnetworkactive(True) | ||||||||
| mn.get_node(self).setnetworkactive(True) | ||||||||
| self.bump_mocktime(60) | ||||||||
|
|
||||||||
| self.log.info("verify that all masternodes re-connected") | ||||||||
| for q in self.nodes[0].quorum('list')['llmq_test']: | ||||||||
| for mn in self.get_quorum_masternodes(q): | ||||||||
| self.wait_for_mnauth(mn.node, expected_connection_count) | ||||||||
| self.wait_for_mnauth(mn.get_node(self), expected_connection_count) | ||||||||
|
|
||||||||
| # Also re-connect non-masternode connections | ||||||||
| for i in range(1, len(self.nodes)): | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix lambda function variable capture issue.
The lambda functions are capturing the loop variable
mnby reference, which could lead to incorrect behavior when the lambda is executed after the loop iteration completes.Apply this fix to properly capture the loop variable:
Apply the same pattern to lines 64 and 69.
Also applies to: 64-64, 69-69
🧰 Tools
🪛 Ruff (0.11.9)
59-59: Function definition does not bind loop variable
mn(B023)
🤖 Prompt for AI Agents