Skip to content

Commit a45d4e3

Browse files
committed
Fix the tests to support the new method for getting the UUID list
As a performance improvement, in 7fac452 we switched to reading the uuids from the UUID database instead of looking at the unique entries in the timeseries. This resulted in an order of magnitude improvement ``` %timeit edb.get_uuid_db().distinct("uuid") 1.29 ms ± 12 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) ``` ``` %timeit edb.get_timeseries_db().distinct("user_id") 3.68 s ± 105 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) ``` But it required that all users have an entry in the UUID DB to show up in the `get_all_uuids()` call. So we change this test to ensure that: - change the existing test loading code to also register users if a `registerEmail` is filled in; this required some refactoring - for this test, pass in a registerEmail in the test object Testing done: ``` $ ./e-mission-py.bash emission/tests/storageTests/TestTimeSeries.py TestTimeSeries.testGetUUIDList storage not configured, falling back to sample, default configuration Connecting to database URL localhost:27017 2021-08-10 12:38:33,424:INFO:4669529536:Before loading from emission/tests/data/real_examples/shankari_2015-aug-21, timeseries db size = 4527962 2021-08-10 12:38:33,471:INFO:4669529536:registering email = user1 Setting up real example for 4405c6ce-f8c8-4e37-b5b7-c69c0072135e 2021-08-10 12:38:37,001:INFO:4669529536:After loading, timeseries db size = 4530087 2021-08-10 12:38:37,019:DEBUG:4669529536:First few entries = ['2015-08-21T07:55:13.408000-07:00', '2015-08-21T07:55:13.408000-07:00', '2015-08-21T07:55:01.638000-07:00', '2015-08-21T07:55:07.414000-07:00', '2015-08-21T07:55:01.638000-07:00', '2015-08-21T07:54:51.095000-07:00', '2015-08-21T07:54:51.095000-07:00', '2015-08-21T07:54:51.095000-07:00', '2015-08-21T07:54:52.153000-07:00', '2015-08-21T07:55:07.414000-07:00'] 2021-08-10 12:38:37,030:INFO:4669529536:Before loading from emission/tests/data/real_examples/shankari_2015-aug-27, timeseries db size = 4530087 2021-08-10 12:38:37,063:INFO:4669529536:registering email = user1 Setting up real example for 4405c6ce-f8c8-4e37-b5b7-c69c0072135e 2021-08-10 12:38:39,418:INFO:4669529536:After loading, timeseries db size = 4531569 2021-08-10 12:38:39,433:DEBUG:4669529536:First few entries = ['2015-08-21T07:55:13.408000-07:00', '2015-08-21T07:55:13.408000-07:00', '2015-08-21T07:55:01.638000-07:00', '2015-08-21T07:55:07.414000-07:00', '2015-08-21T07:55:01.638000-07:00', '2015-08-21T07:54:51.095000-07:00', '2015-08-21T07:54:51.095000-07:00', '2015-08-21T07:54:51.095000-07:00', '2015-08-21T07:54:52.153000-07:00', '2015-08-21T07:55:07.414000-07:00'] . ---------------------------------------------------------------------- Ran 1 test in 6.193s OK ```
1 parent 6cc353a commit a45d4e3

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

emission/tests/common.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,26 @@ def getRealExampleEmail(testObj):
106106
def fillExistingUUID(testObj):
107107
userObj = ecwu.User.fromEmail(getRealExampleEmail(testObj))
108108
print("Setting testUUID to %s" % userObj.uuid)
109-
testObj.testUUID = userObj.uuid
109+
testObj.testUUID = userObj.uuir
110110

111-
def createAndFillUUID(testObj):
111+
def getRegEmailIfPresent(testObj):
112112
if hasattr(testObj, "evaluation") and testObj.evaluation:
113+
logging.info("evaluation, returning email = %s" % reg_email)
113114
reg_email = getRealExampleEmail(testObj)
114-
logging.info("registering email = %s" % reg_email)
115-
user = ecwu.User.register(reg_email)
115+
return reg_email
116+
elif hasattr(testObj, "testEmail"):
117+
return testObj.testEmail
118+
else:
119+
return None
120+
121+
def createAndFillUUID(testObj):
122+
regEmail = getRegEmailIfPresent(testObj)
123+
if regEmail is not None:
124+
logging.info("registering email = %s" % regEmail)
125+
user = ecwu.User.register(regEmail)
116126
testObj.testUUID = user.uuid
117127
else:
118-
logging.info("No evaluation flag found, not registering email")
128+
logging.info("No reg email found, not registering email")
119129
testObj.testUUID = uuid.uuid4()
120130

121131
def setupRealExample(testObj, dump_file):

emission/tests/storageTests/TestTimeSeries.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
class TestTimeSeries(unittest.TestCase):
2828
def setUp(self):
29+
self.testEmail = "user1"
2930
etc.setupRealExample(self, "emission/tests/data/real_examples/shankari_2015-aug-21")
3031
self.testUUID1 = self.testUUID
3132
self.entries1 = self.entries
33+
34+
self.testEmail = "user1"
3235
etc.setupRealExample(self, "emission/tests/data/real_examples/shankari_2015-aug-27")
3336

3437
def tearDown(self):

0 commit comments

Comments
 (0)