Merge ~cjwatson/launchpad:shorten-test-instance-name into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 63cfd8fc38085761e59d51c77e220e16ef5e7800
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:shorten-test-instance-name
Merge into: launchpad:master
Diff against target: 35 lines (+8/-2)
1 file modified
lib/lp/testing/layers.py (+8/-2)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+415903@code.launchpad.net

Commit message

Use slightly shorter test DB instance names

Description of the change

Process IDs may nowadays be up to seven digits long, so the previous test database instance names we used could cause 'launchpad_ftest_template_{test_instance}' to be up to 65 characters long; but PostgreSQL identifiers are limited to 63 characters, so this could cause the tests in `lp.services.webapp.tests.test_dbpolicy.TestFastDowntimeRollout` to fail. Use a slightly shorter random suffix to compensate for this.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/testing/layers.py b/lib/lp/testing/layers.py
2index d27ca18..1b6fcb0 100644
3--- a/lib/lp/testing/layers.py
4+++ b/lib/lp/testing/layers.py
5@@ -45,6 +45,7 @@ __all__ = [
6 'reconnect_stores',
7 ]
8
9+import base64
10 from cProfile import Profile
11 import datetime
12 import errno
13@@ -64,7 +65,6 @@ from unittest import (
14 TestCase,
15 TestResult,
16 )
17-import uuid
18
19 from fixtures import (
20 Fixture,
21@@ -277,7 +277,13 @@ class BaseLayer:
22 # We can only do unique test allocation and parallelisation if
23 # LP_PERSISTENT_TEST_SERVICES is off.
24 if not BaseLayer.persist_test_services:
25- test_instance = '%d_%s' % (os.getpid(), uuid.uuid1().hex)
26+ # This should be at most 38 characters long, otherwise
27+ # 'launchpad_ftest_template_{test_instance}' won't fit within
28+ # PostgreSQL's 63-character limit for identifiers. Linux
29+ # currently allows up to 2^22 PIDs, so PIDs may be up to seven
30+ # digits long.
31+ test_instance = '%d_%s' % (
32+ os.getpid(), base64.b16encode(os.urandom(12)).decode().lower())
33 os.environ['LP_TEST_INSTANCE'] = test_instance
34 cls.fixture.addCleanup(os.environ.pop, 'LP_TEST_INSTANCE', '')
35 # Kill any Memcached or Librarian left running from a previous

Subscribers

People subscribed via source and target branches

to status/vote changes: