1. Marc-Alexandre Chan
  2. DailyPromptBot

Commits

Marc-Alexandre Chan  committed 76ee380

[TEST] More scheduler test code

  • Participants
  • Parent commits 4bcd4f7
  • Branches dev-minibot

Comments (0)

Files changed (1)

File minibot/config/localtest/notes-scheduler.txt

View file
  • Ignore whitespace
           EventMock("Final error", now+18, 0, 0),
           EventMock("OMGWTFBBQ", now+14, 0, 0)]
 
+# for stop test
+#events = [EventMock("stop", now+2, 7, 2, end_fn=scheduler.request_stop),
+#          EventMock("Four in twenty seconds", now+4, 11, 3)]
+# for exit test
+#events = [EventMock("exit", now+2, 7, 2, end_fn=scheduler.request_exit),
+#          EventMock("Four in twenty seconds", now+4, 11, 3)]
+
 random.shuffle(events) # to check if things are queued in the right order
-print events # take a look at the shuffled order
-  
+print 'Randomised: ', events, '\n' # take a look at the shuffled order
+
 for ev in events:
     if ev.name == "Retry error":
         ev.raise_error = ev.ERR_RETRY
     elif ev.name == "OMGWTFBBQ":
         ev.raise_error = ev.ERR_UNHANDLED
     scheduler.queue_event(ev)
-    
+
 # now can inspect scheduler state and execute scheduler.run()
 print '\n'.join([' '.join([x.name, '%.3f'% (x.start_time-now), '%.3f'%x.duration, '%.3f'%x.interval]) for x in scheduler.get_events()])
 print '\n'
-print '\n'.join([' '.join([w.name, '%.3f'% (x-now), '%.3f'%w.duration, '%.3f'%w.interval]) for x, y, z, w in scheduler._queue])
-# scheduler.run()
+# print '\n'.join([' '.join([w.name, '%.3f'% (x-now), '%.3f'%w.duration, '%.3f'%w.interval]) for x, y, z, w in scheduler._queue])
+# print '\n'
+
+print 'now: ', now
+scheduler.run()
+# also try setting some events (start_fn or end_fn constructor arg) to stop or exit the scheduler to test that functionality
+print '\n'
+
+sequence = []
+for ev in events:
+    if ev.started:
+        sequence.append((ev.started-now, ev.name, 'started'))
+    if ev.ended:
+        sequence.append((ev.ended-now, ev.name, 'ended'))
+    sequence.extend([(time-now, ev.name, 'run') for time in ev.run_times])
+for x in sorted(sequence):
+    print x