Skip to content

Commit

Permalink
Merge pull request buildbot#8232 from p12tic/test-fix-real-database-s…
Browse files Browse the repository at this point in the history
…election

test: Reuse resolve_test_db_url() in fakemaster.make_master()
  • Loading branch information
p12tic authored Dec 2, 2024
2 parents 385da0c + 1211153 commit 7923641
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 79 deletions.
12 changes: 5 additions & 7 deletions master/buildbot/test/fake/fakemaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from buildbot.test.fake.botmaster import FakeBotMaster
from buildbot.test.fake.machine import FakeMachineManager
from buildbot.test.fake.secrets import FakeSecretStorage
from buildbot.test.util.db import resolve_test_db_url
from buildbot.util import service
from buildbot.util.twisted import async_to_deferred

Expand Down Expand Up @@ -167,7 +168,7 @@ async def make_master(
wantGraphql=False,
with_secrets: dict | None = None,
url=None,
db_url='sqlite://',
db_url=None,
sqlite_memory=True,
auto_upgrade=True,
auto_shutdown=True,
Expand Down Expand Up @@ -202,17 +203,14 @@ async def make_master(
)
master._test_want_db = True

if db_url == 'sqlite://' and not sqlite_memory:
db_url = 'sqlite:///tmp.sqlite'
if not os.path.exists(master.basedir):
os.makedirs(master.basedir)

if auto_shutdown:
# Add before setup so that failed database setup would still be closed and wouldn't
# affect further tests
testcase.addCleanup(master.test_shutdown)

master.db.configured_url = db_url
master.db.configured_url = resolve_test_db_url(db_url, sqlite_memory)
if not os.path.exists(master.basedir):
os.makedirs(master.basedir)
await master.db.set_master(master)
await master.db.setup()

Expand Down
6 changes: 4 additions & 2 deletions master/buildbot/test/integration/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@ def setUpUpgradeTest(self):
# get the top-level dir from the tarball
assert len(prefixes) == 1, "tarball has multiple top-level dirs!"
self.basedir = prefixes.pop()
db_url = 'sqlite:///' + os.path.abspath(os.path.join(self.basedir, 'state.sqlite'))
else:
if not os.path.exists("basedir"):
os.makedirs("basedir")
self.basedir = os.path.abspath("basedir")
db_url = None

self.master = yield fakemaster.make_master(
self,
basedir=self.basedir,
wantDb=True,
db_url='sqlite:///' + os.path.abspath(os.path.join(self.basedir, 'state.sqlite')),
db_url=db_url,
sqlite_memory=False,
auto_upgrade=False,
check_version=False,
auto_clean=False,
auto_clean=False if self.source_tarball else True,
)

self._sql_log_handler = querylog.start_log_queries()
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/test/unit/process/test_users_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def test_perspective_commandline_remove(self):
yield self.call_perspective_commandline(
'add', None, None, None, [{'identifier': 'h@c', 'git': 'hi <h@c>'}]
)
yield self.call_perspective_commandline('remove', None, None, ['x'], None)
res = yield self.master.db.users.getUser('x')
yield self.call_perspective_commandline('remove', None, None, ['h@c'], None)
res = yield self.master.db.users.getUser(1)
self.assertEqual(res, None)

@defer.inlineCallbacks
Expand Down
11 changes: 10 additions & 1 deletion master/buildbot/test/unit/reporters/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
from buildbot.test.util import logging


def sort_builds(builds):
return sorted(builds, key=lambda key: key['buildid'])


class TestDataUtils(TestReactorMixin, unittest.TestCase, logging.LoggingMixin):
LOGCONTENT = textwrap.dedent("""\
line zero
Expand Down Expand Up @@ -174,6 +178,9 @@ def test_getDetailsForBuildset(self):
self.master, 98, want_properties=True, want_steps=True, want_previous_build=True
)
self.assertEqual(len(res['builds']), 2)

res['builds'] = sort_builds(res['builds'])

build1 = res['builds'][0]
build2 = res['builds'][1]
buildset = res['buildset']
Expand Down Expand Up @@ -239,7 +246,7 @@ def test_getDetailsForBuildsetWithLogs(self):
want_logs_content=True,
)

build1 = res['builds'][0]
build1 = sort_builds(res['builds'])[0]
self.assertEqual(
build1['steps'][0]['logs'][0]['content']['content'], self.LOGCONTENT + "\n"
)
Expand All @@ -262,6 +269,8 @@ def test_get_details_for_buildset_all(self):
want_logs_content=True,
)

res['builds'] = sort_builds(res['builds'])

self.assertEqual(
res,
{
Expand Down
Loading

0 comments on commit 7923641

Please sign in to comment.