Skip to content
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

LB-187: Add NOT NULL constraint to the last_login field #214

Merged
merged 4 commits into from Aug 17, 2017

Conversation

paramsingh
Copy link
Collaborator

Fix issues pointed out by @alastair in this review: #189 (review)

Also, some refactoring to make the `update_last_login` function
use PostgreSQL's NOW() method, considering we never change
the `last_login` value to anything else.
@@ -0,0 +1,12 @@
BEGIN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in acousticbrainz we put the date in the filenames of update scripts, to make a it a little easier to know in what order to run things. Should we do this here too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files renamed.

user = db_user.get_by_mb_id(user['musicbrainz_id'])
self.assertEqual(val, int(user['last_login'].strftime('%s')))
# after update_last_login, the val should be equal to the current time
self.assertEqual(int(time.time()), int(user['last_login'].strftime('%s')))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is dangerous, because 99% of the time it might work, but then suddenly there may be a case where we do the above line just before the time increases by a second.
I would prefer to create a user with a last login time obviously in the past - you could do this by doing an sql query to get now() - interval 1 day or choose some time in june 2017 - and then do the update and check that this value is greater than the original value that you set it to

Copy link
Collaborator Author

@paramsingh paramsingh Jul 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I actually thought that this could be a problem when writing the test, should have done this from the beginning, done now!

First run an SQL query to update the last login value to
unix epoch. Then call the function and assert that the
value now is greater than 0.
Copy link
Member

@mayhem mayhem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets tighten up that test case.

self.assertEqual(val, int(user['last_login'].strftime('%s')))

# after update_last_login, the val should be greater than the old value i.e 0
self.assertGreater(int(user['last_login'].strftime('%s')), 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a bit iffy to me. I think you should get the current time, save it, then ensure that the DB got updated to that time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require changing the function to take a timestamp parameter and update to that timestamp, which is what alastair wanted changed here: #189 (comment)

Initially I had written the test like you are suggesting here but we changed it here with alastair's review: #214 (comment)

Should I go back to taking a timestamp in the function and not using NOW()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naw, lets just improve the test once #189 is implemented. But in general giving a timestamp makes more sense, because it allows the caller to determine what to do.

Copy link
Member

@mayhem mayhem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕋 +🐷 = 🤕 ?

@mayhem mayhem merged commit 6acada6 into metabrainz:master Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants