-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fix modify and save test, add "updated" to modify #416
base: develop
Are you sure you want to change the base?
Changes from all commits
e9ac3c2
b3884a6
a8cc2ae
606d292
18b0109
9dc9fdf
6404b86
0b65043
400c1ab
f16943a
ad74923
dd8cfcf
36cbb6f
1d977a6
cac5241
c3e08b3
a7256a4
f55ab10
27ef29a
2a0722f
9bbbd61
d857a37
add6f44
a637bb4
9be3578
0183f98
af03d77
76fcb1a
3d517d9
8e19ccf
2822e77
ac4b6af
f244544
20d0b34
afaba4c
0cc6b6b
24d9783
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import os | ||
import unittest | ||
from datetime import datetime | ||
|
||
import json | ||
from bson.objectid import ObjectId | ||
|
||
from execution_engine2.db.MongoUtil import MongoUtil | ||
|
@@ -58,17 +58,55 @@ def test_init_ok(self): | |
mongo_util = self.getMongoUtil() | ||
self.assertTrue(set(class_attri) <= set(mongo_util.__dict__.keys())) | ||
|
||
def test_save_and_modify_updates_timestamp(self): | ||
job = get_example_job(status=Status.created.value) | ||
updated_ts = job.updated | ||
job.save() | ||
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. Its seems a bit odd that saving a job updates the timestamp even if there are no changes, is that what you want? 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. Well, updated tracks the last time the job was saved or modified, so seems ok to me. What do you suggest? 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. I mean updated to me means that the job was updated, e.g. changed in some way. It doesn't make sense to me for the updated timestamp to change if the job hasn't changed 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. Alright, so if we make sure to only save jobs with changes, then we should be alright? 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. I'm not sure if its possible to know if a record has a different value or not when saving unless we reload the record or do two saves? 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.
I think so, but we should document the behavior clearly 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.
You can do a query on the entire record, but that's probably overkill. It'd be nice if Mongo had a feature where a field would only be updated if at least one of a set of provided fields changed |
||
job.reload() | ||
new_updated_ts = job.updated | ||
assert new_updated_ts > updated_ts | ||
# Now check modify | ||
job.modify(add_to_set__child_jobs=["a"]) | ||
assert job.updated > new_updated_ts | ||
|
||
def test_insert_jobs(self): | ||
"""Check to see that jobs are inserted into mongo""" | ||
job = get_example_job(status=Status.created.value) | ||
job2 = get_example_job(status=Status.created.value) | ||
job3 = get_example_job(status=Status.created.value) | ||
# job3.updated = datetime.utcnow().timestamp() | ||
|
||
json_repr = [job.to_json(), job2.to_json(), job3.to_json()] | ||
mongo_repr = [job.to_mongo(), job2.to_mongo(), job3.to_mongo()] | ||
|
||
jobs_to_insert = [job, job2] | ||
job_ids = self.getMongoUtil().insert_jobs(jobs_to_insert) | ||
assert len(job_ids) == len(jobs_to_insert) | ||
retrieved_jobs = self.getMongoUtil().get_jobs(job_ids=job_ids) | ||
|
||
for i, retrieved_job in enumerate(retrieved_jobs): | ||
assert jobs_to_insert[i].to_json() == retrieved_job.to_json() | ||
original_job_json = json.loads(json_repr[i]) | ||
original_job_mongo = mongo_repr[i] | ||
|
||
retrieved_job_json = json.loads(retrieved_job.to_json()) | ||
retrieved_job_mongo = retrieved_job.to_mongo() | ||
|
||
# Cannot compare `id` or `updated` for a job that wasn't yet saved, | ||
# and save/updates over-write the updated timestamp | ||
# so we should remove them before comparison | ||
|
||
for item in [ | ||
original_job_json, | ||
original_job_mongo, | ||
retrieved_job_mongo, | ||
retrieved_job_json, | ||
]: | ||
for field in ["updated", "_id"]: | ||
if field in item: | ||
del item[field] | ||
|
||
assert original_job_json == retrieved_job_json | ||
assert original_job_mongo == retrieved_job_mongo | ||
|
||
def test_update_jobs_enmasse(self): | ||
"""Check to see that created jobs get updated to queued""" | ||
|
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.
Shouldn't this just pass the query as is, not pass
None
?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.
Assuming I understand this I guess no code uses the query field otherwise tests should've broken
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.
Yea it should pass the query good call
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.
how did the tests pass with this bug?