Mercurial > p > roundup > code
comparison test/session_common.py @ 6806:bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
The data types used to represent timestamps in pg and mysql for
ephemeral tables: sessions and otks don't have enough signifcant
digits to work. As a result the timestamps are rounduped (up/down)
rsuling in the stored timestamp being 2 minutes (pg) or 2-3
hours(mysql) off from what it should be.
Modify db schema to use a numeric type that preserves more significant
figures. Implement schema upgrade. Document need for upgrade in
upgrading.txt.
Write tests for schema upgrade.
Implement test for updateTimestamp method on BasicDatabase that showed
this issue in the first place. Write overrides for test for
anydbm/memorydb which store timestamp properly or not at all.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 25 Jul 2022 17:20:20 -0400 |
| parents | 044dcf3608a2 |
| children | 375d40a9e730 |
comparison
equal
deleted
inserted
replaced
| 6805:09d9c646ca89 | 6806:bdd28b244839 |
|---|---|
| 57 self.assertEqual(self.sessions.get('random_key', 'text'), | 57 self.assertEqual(self.sessions.get('random_key', 'text'), |
| 58 'hello, world!') | 58 'hello, world!') |
| 59 self.sessions.set('random_key', text='nope') | 59 self.sessions.set('random_key', text='nope') |
| 60 self.assertEqual(self.sessions.get('random_key', 'text'), 'nope') | 60 self.assertEqual(self.sessions.get('random_key', 'text'), 'nope') |
| 61 | 61 |
| 62 # overridden in dbm and memory backends | |
| 63 def testUpdateTimestamp(self): | |
| 64 def get_ts_via_sql(self): | |
| 65 sql = '''select %(name)s_time from %(name)ss | |
| 66 where %(name)s_key = '%(session)s';'''% \ | |
| 67 {'name': self.sessions.name, | |
| 68 'session': 'random_session'} | |
| 69 | |
| 70 self.sessions.cursor.execute(sql) | |
| 71 db_tstamp = self.sessions.cursor.fetchone() | |
| 72 return db_tstamp | |
| 73 | |
| 74 # make sure timestamp is older than one minute so update will apply | |
| 75 timestamp = time.time() - 62 | |
| 76 self.sessions.set('random_session', text='hello, world!', | |
| 77 __timestamp=timestamp) | |
| 78 | |
| 79 self.sessions.updateTimestamp('random_session') | |
| 80 # this doesn't work as the rdbms backends have a | |
| 81 # session_time, otk_time column and the timestamp in the | |
| 82 # session marshalled payload isn't updated. The dbm | |
| 83 # backend does update the __timestamp value so it works | |
| 84 # for dbm. | |
| 85 #self.assertNotEqual (self.sessions.get('random_session', | |
| 86 # '__timestamp'), | |
| 87 # timestamp) | |
| 88 | |
| 89 # use 61 to allow a fudge factor | |
| 90 self.assertGreater(get_ts_via_sql(self)[0] - timestamp, 61) |
