Browse code

add test for 'stop_after' goal

Joseph Weston authored on 21/11/2019 12:33:08
Showing 1 changed files
... ...
@@ -1,6 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3 3
 import asyncio
4
+import time
4 5
 
5 6
 import pytest
6 7
 
... ...
@@ -10,6 +11,7 @@ from adaptive.runner import (
10 11
     BlockingRunner,
11 12
     SequentialExecutor,
12 13
     simple,
14
+    stop_after,
13 15
     with_distributed,
14 16
     with_ipyparallel,
15 17
 )
... ...
@@ -103,6 +105,14 @@ def test_concurrent_futures_executor():
103 105
     )
104 106
 
105 107
 
108
+def test_stop_after_goal():
109
+    seconds_to_wait = 0.2  # don't make this too large or the test will take ages
110
+    start_time = time.time()
111
+    BlockingRunner(Learner1D(linear, (-1, 1)), stop_after(seconds=seconds_to_wait))
112
+    stop_time = time.time()
113
+    assert stop_time - start_time > seconds_to_wait
114
+
115
+
106 116
 @pytest.mark.skipif(not with_ipyparallel, reason="IPyparallel is not installed")
107 117
 def test_ipyparallel_executor(ipyparallel_executor):
108 118
     learner = Learner1D(linear, (-1, 1))