<s> """<STR_LIT>""" <EOL> import threading <EOL> import time <EOL> import unittest <EOL> from google . appengine . tools . devappserver2 import scheduled_executor <EOL> class FakeThreadPool ( object ) : <EOL> def submit ( self , runnable , * args , ** kwargs ) : <EOL> runnable ( * args , ** kwargs ) <EOL> class ScheduledExecutorTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . executor = scheduled_executor . ScheduledExecutor ( FakeThreadPool ( ) ) <EOL> self . executor . start ( ) <EOL> def tearDown ( self ) : <EOL> self . executor . quit ( ) <EOL> def test_add_and_execute ( self ) : <EOL> event = threading . Event ( ) <EOL> self . executor . add_event ( event . set , time . time ( ) + <NUM_LIT:3> ) <EOL> event . wait ( <NUM_LIT:5> ) <EOL> self . assertTrue ( event . is_set ( ) ) <EOL> def test_add_two_with_same_eta_and_execute ( self ) : <EOL> event = threading . Event ( ) <EOL> event2 = threading . Event ( ) <EOL> eta = time . time ( ) + <NUM_LIT:3> <EOL> self . executor . add_event ( event . set , eta ) <EOL> self . executor . add_event ( event2 . set , eta ) <EOL> event . wait ( <NUM_LIT:5> ) <EOL> event2 . wait ( <NUM_LIT:5> ) <EOL> self . assertTrue ( event . is_set ( ) ) <EOL> self . assertTrue ( event2 . is_set ( ) ) <EOL> def test_add_and_update_and_execute ( self ) : <EOL> event = threading . Event ( ) <EOL> self . executor . add_event ( event . set , time . time ( ) + <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> self . executor . update_event ( time . time ( ) + <NUM_LIT:1000> , <NUM_LIT:0> ) <EOL> event . wait ( <NUM_LIT:5> ) <EOL> self . assertFalse ( event . is_set ( ) ) <EOL> def test_add_and_update_different_event_and_execute ( self ) : <EOL> event = threading . Event ( ) <EOL> self . executor . add_event ( event . set , time . time ( ) + <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> self . executor . update_event ( time . time ( ) + <NUM_LIT:1000> , <NUM_LIT:0> ) <EOL> event . wait ( <NUM_LIT:5> ) <EOL> self . assertTrue ( event . is_set ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
