Skip to content

Commit

Permalink
Merge #6216: fix: intermittent failures in governance tests with tsan
Browse files Browse the repository at this point in the history
291716a refactor: move common duplicated code to test_framework/governance.py (Konstantin Akimov)
f16b998 fix: intermittent failure in feature_governance.py by bump timeout (Konstantin Akimov)
c3d5858 fix: intermittent failure in feature_governance_cl by bumping timeout (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  Intermittent failure in functional tests feature_governance and feature_governance_cl:
   - https://gitlab.com/dashpay/dash/-/jobs/7574959798
   - https://gitlab.com/dashpay/dash/-/jobs/7574917439
   - https://gitlab.com/dashpay/dash/-/jobs/7576050419

  and many other

  ## What was done?
  Bump timeout in `feature_governance.py`, `feature_governance_cl.py`; moved code from them to `test_framework/governance.py`

  ## How Has This Been Tested?
  Run unit/functional tests in 40 threads locally: amount of failures decreased from 50% to 2.5%
  ```
  test/functional/test_runner.py -j40  feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance_cl.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py feature_governance.py
  ```

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [x] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

ACKs for top commit:
  PastaPastaPasta:
    utACK 291716a
  UdjinM6:
    utACK 291716a

Tree-SHA512: 9e62aad2c79817c7d549e5526a71029c2a363b700de847637622c0c180a8c693eb3b47b32cddfd9f98ceaa95614449b13c60dbd74b381858bae9e5a1dc47358e
  • Loading branch information
PastaPastaPasta committed Aug 20, 2024
2 parents d8fca38 + 291716a commit 09a7e55
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 78 deletions.
46 changes: 6 additions & 40 deletions test/functional/feature_governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from test_framework.messages import uint256_to_string
from test_framework.test_framework import DashTestFramework
from test_framework.governance import have_trigger_for_height, prepare_object
from test_framework.util import assert_equal, satoshi_round, set_node_times, wait_until_helper

class DashGovernanceTest (DashTestFramework):
Expand All @@ -16,29 +17,6 @@ def set_test_params(self):
# using adjusted v20 deployment params to test an edge case where superblock maturity window is equal to deployment window size
self.set_dash_test_params(6, 5, [["-budgetparams=10:10:10", f"-vbparams=v20:{self.v20_start_time}:999999999999:0:10:8:6:5:0"]] * 6, fast_dip3_enforcement=True)

def prepare_object(self, object_type, parent_hash, creation_time, revision, name, amount, payment_address):
proposal_rev = revision
proposal_time = int(creation_time)
proposal_template = {
"type": object_type,
"name": name,
"start_epoch": proposal_time,
"end_epoch": proposal_time + 24 * 60 * 60,
"payment_amount": float(amount),
"payment_address": payment_address,
"url": "https://dash.org"
}
proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_template).encode())
collateral_hash = self.nodes[0].gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex)
return {
"parentHash": parent_hash,
"collateralHash": collateral_hash,
"createdAt": proposal_time,
"revision": proposal_rev,
"hex": proposal_hex,
"data": proposal_template,
}

def check_superblockbudget(self, v20_active):
v20_state = self.nodes[0].getblockchaininfo()["softforks"]["v20"]
assert_equal(v20_state["active"], v20_active)
Expand Down Expand Up @@ -77,18 +55,6 @@ def check_superblock(self):

assert_equal(payments_found, 2)

def have_trigger_for_height(self, sb_block_height):
count = 0
for node in self.nodes:
valid_triggers = node.gobject("list", "valid", "triggers")
for trigger in list(valid_triggers.values()):
if json.loads(trigger["DataString"])["event_block_height"] != sb_block_height:
continue
if trigger['AbsoluteYesCount'] > 0:
count = count + 1
break
return count == len(self.nodes)

def run_test(self):
governance_info = self.nodes[0].getgovernanceinfo()
assert_equal(governance_info['governanceminquorum'], 1)
Expand Down Expand Up @@ -152,9 +118,9 @@ def run_test(self):
self.p1_amount = satoshi_round("3.3")
self.p2_amount = self.expected_v20_budget - self.p1_amount

p0_collateral_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_0", self.p0_amount, self.p0_payout_address)
p1_collateral_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address)
p2_collateral_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_2", self.p2_amount, self.p2_payout_address)
p0_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_0", self.p0_amount, self.p0_payout_address)
p1_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address)
p2_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_2", self.p2_amount, self.p2_payout_address)

self.nodes[0].generate(6)
self.bump_mocktime(6)
Expand Down Expand Up @@ -348,7 +314,7 @@ def sync_gov(node):
self.bump_mocktime(1)
self.sync_blocks()
# Wait for new trigger and votes
self.wait_until(lambda: self.have_trigger_for_height(260), timeout=5)
self.wait_until(lambda: have_trigger_for_height(self.nodes, 260))
# Mine superblock
self.nodes[0].generate(1)
self.bump_mocktime(1)
Expand All @@ -364,7 +330,7 @@ def sync_gov(node):
self.sync_blocks()
# Wait for new trigger and votes
sb_block_height = 260 + (i + 1) * sb_cycle
self.wait_until(lambda: self.have_trigger_for_height(sb_block_height), timeout=5)
self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height))
# Mine superblock
self.nodes[0].generate(1)
self.bump_mocktime(1)
Expand Down
17 changes: 2 additions & 15 deletions test/functional/feature_governance_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import json

from test_framework.governance import have_trigger_for_height
from test_framework.messages import uint256_to_string
from test_framework.test_framework import DashTestFramework
from test_framework.util import assert_equal, force_finish_mnsync, satoshi_round
Expand Down Expand Up @@ -37,20 +38,6 @@ def prepare_object(self, object_type, parent_hash, creation_time, revision, name
"data": proposal_template,
}

def have_trigger_for_height(self, sb_block_height, nodes = None):
if nodes is None:
nodes = self.nodes
count = 0
for node in nodes:
valid_triggers = node.gobject("list", "valid", "triggers")
for trigger in list(valid_triggers.values()):
if json.loads(trigger["DataString"])["event_block_height"] != sb_block_height:
continue
if trigger['AbsoluteYesCount'] > 0:
count = count + 1
break
return count == len(nodes)

def run_test(self):
sb_cycle = 20

Expand Down Expand Up @@ -123,7 +110,7 @@ def run_test(self):

self.log.info("Wait for new trigger and votes on non-isolated nodes")
sb_block_height = self.nodes[0].getblockcount() + 1
self.wait_until(lambda: self.have_trigger_for_height(sb_block_height, self.nodes[0:5]), timeout=5)
self.wait_until(lambda: have_trigger_for_height(self.nodes[0:5], sb_block_height))
# Mine superblock
self.nodes[0].generate(1)
self.bump_mocktime(156)
Expand Down
26 changes: 3 additions & 23 deletions test/functional/feature_governance_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Tests around dash governance objects."""

import json
import time

from test_framework.governance import prepare_object
from test_framework.messages import uint256_to_string
from test_framework.test_framework import DashTestFramework
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error
Expand All @@ -21,33 +21,13 @@ def validate_object(prepared, rpc_prepared):
del rpc_prepared["data"]["hex"]
assert_equal(prepared["data"], rpc_prepared["data"])


class DashGovernanceTest (DashTestFramework):
def set_test_params(self):
self.set_dash_test_params(2, 1)

def prepare_object(self, object_type, parent_hash, creation_time, revision, name, amount):
proposal_rev = revision
proposal_time = int(creation_time)
proposal_template = {
"type": object_type,
"name": name,
"start_epoch": proposal_time,
"end_epoch": proposal_time + 24 * 60 * 60,
"payment_amount": amount,
"payment_address": self.nodes[0].getnewaddress(),
"url": "https://dash.org"
}
proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_template).encode())
collateral_hash = self.nodes[0].gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex)
return {
"parentHash": parent_hash,
"collateralHash": collateral_hash,
"createdAt": proposal_time,
"revision": proposal_rev,
"hex": proposal_hex,
"data": proposal_template,
}
payment_address = self.nodes[0].getnewaddress()
return prepare_object(self.nodes[0], object_type, parent_hash, creation_time, revision, name, amount, payment_address)

def run_test(self):

Expand Down
43 changes: 43 additions & 0 deletions test/functional/test_framework/governance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# Copyright (c) 2018-2024 The Dash Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Utils for dash governance tests."""

import json

def prepare_object(node, object_type, parent_hash, creation_time, revision, name, amount, payment_address):
proposal_rev = revision
proposal_time = int(creation_time)
proposal_template = {
"type": object_type,
"name": name,
"start_epoch": proposal_time,
"end_epoch": proposal_time + 24 * 60 * 60,
"payment_amount": float(amount),
"payment_address": payment_address,
"url": "https://dash.org"
}
proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_template).encode())
collateral_hash = node.gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex)
return {
"parentHash": parent_hash,
"collateralHash": collateral_hash,
"createdAt": proposal_time,
"revision": proposal_rev,
"hex": proposal_hex,
"data": proposal_template,
}

def have_trigger_for_height(nodes, sb_block_height):
count = 0
for node in nodes:
valid_triggers = node.gobject("list", "valid", "triggers")
for trigger in list(valid_triggers.values()):
if json.loads(trigger["DataString"])["event_block_height"] != sb_block_height:
continue
if trigger['AbsoluteYesCount'] > 0:
count = count + 1
break
return count == len(nodes)

0 comments on commit 09a7e55

Please sign in to comment.