2 Test the cron jobs scheduling.
4 Disable the existing cron jobs if any during the tests.
6 !python {model: ir.cron }: |
7 # For this test to work, as it involves multiple database cursors,
8 # we have to commit changes. But YAML tests must be rollbacked, so
9 # the final database state is left untouched. So we have to be a bit
10 # ugly here: use our own cursor, commit, and clean after ourselves.
11 # We also pass around some ids using setattr/delattr, and we have to
12 # rollback the previous tests otherwise we won't be able to touch the
14 # Well, this should probably be a standalone, or regular unit test,
15 # instead of using the YAML infrastructure.
17 our_cr = self.pool.db.cursor()
19 ids = self.search(our_cr, uid, [], {})
20 setattr(self, 'saved_ids', ids)
21 self.write(our_cr, uid, ids, {'active': False}, {})
26 Three concurrent jobs started with a slight time gap. Assume 4 cron threads.
27 This will take about 2 minutes.
29 !python {model: ir.cron }: |
30 # Pretend initialization is already done. We the use a try/finally
31 # to reset _init correctly.
32 self.pool._init = False
33 our_cr = self.pool.db.cursor()
35 self.test_00(our_cr, uid) # this will commit using the passed cursor
37 openerp.cron._thread_slots = 4
38 # Wake up this db as soon as the master cron thread starts.
39 openerp.cron.schedule_wakeup(1, self.pool.db.dbname)
40 # Pretend to be the master thread, for 4 iterations.
41 openerp.cron.runner_body()
42 openerp.cron.runner_body()
43 openerp.cron.runner_body()
44 openerp.cron.runner_body()
46 self.pool._init = True
49 Clean after ourselves.
51 !python {model: ir.cron }: |
52 our_cr = self.pool.db.cursor()
54 ids = [x for x in self.search(our_cr, uid, ['|', ('active', '=', True), ('active', '=', False)], {}) if x not in self.saved_ids]
55 self.unlink(our_cr, uid, ids, {})
57 delattr(self, 'saved_ids')
58 self.write(our_cr, uid, ids, {'active': True}, {})