@@ -127,13 +127,18 @@ def curtime(x: ts[object]) -> ts[datetime]:
127
127
return csp .now ()
128
128
129
129
def graph (symbols : list , count : int ):
130
- b = csp .merge (
131
- csp .timer (timedelta (seconds = 0.2 ), True ),
132
- csp .delay (csp .timer (timedelta (seconds = 0.2 ), False ), timedelta (seconds = 0.1 )),
130
+ delay = timedelta (seconds = 1 )
131
+ b = csp .delay (
132
+ csp .merge (
133
+ csp .timer (timedelta (seconds = 0.2 ), True ),
134
+ csp .delay (csp .timer (timedelta (seconds = 0.2 ), False ), timedelta (seconds = 0.1 )),
135
+ ),
136
+ delay = delay ,
133
137
)
134
- i = csp .count (csp .timer (timedelta (seconds = 0.15 )))
135
- d = csp .count (csp .timer (timedelta (seconds = 0.2 ))) / 2.0
136
- s = csp .sample (csp .timer (timedelta (seconds = 0.4 )), csp .const ("STRING" ))
138
+
139
+ i = csp .delay (csp .count (csp .timer (timedelta (seconds = 0.15 ))), delay = delay )
140
+ d = csp .delay (csp .count (csp .timer (timedelta (seconds = 0.2 ))) / 2.0 , delay = delay )
141
+ s = csp .delay (csp .sample (csp .timer (timedelta (seconds = 0.4 )), csp .const ("STRING" )), delay = delay )
137
142
dt = curtime (b )
138
143
struct = MyData .collectts (b = b , i = i , d = d , s = s , dt = dt )
139
144
@@ -157,18 +162,13 @@ def graph(symbols: list, count: int):
157
162
)
158
163
csp .add_graph_output (f"pall_{ symbol } " , pub_data )
159
164
160
- # csp.print('status', kafkaadapter.status())
161
-
162
165
sub_data = kafkaadapter .subscribe (
163
166
ts_type = SubData ,
164
167
msg_mapper = msg_mapper ,
165
168
topic = topic ,
166
169
key = symbol ,
167
170
push_mode = csp .PushMode .NON_COLLAPSING ,
168
171
)
169
-
170
- sub_data = csp .firstN (sub_data , count )
171
-
172
172
csp .add_graph_output (f"sall_{ symbol } " , sub_data )
173
173
174
174
done_flag = csp .count (sub_data ) == count
@@ -190,8 +190,12 @@ def graph(symbols: list, count: int):
190
190
pub = results [f"pall_{ symbol } " ]
191
191
sub = results [f"sall_{ symbol } " ]
192
192
193
+ # limit by the last `count`
194
+ sub = sub [- 1 * count :]
195
+ pub = pub [- 1 * count :]
196
+
193
197
assert len (sub ) == count
194
- assert [v [1 ] for v in sub ] == [v [1 ] for v in pub [: count ]]
198
+ assert [v [1 ] for v in sub ] == [v [1 ] for v in pub [- 1 * count : ]]
195
199
196
200
@pytest .mark .skipif (not os .environ .get ("CSP_TEST_KAFKA" ), reason = "Skipping kafka adapter tests" )
197
201
def test_start_offsets (self , kafkaadapter , kafkabroker ):
0 commit comments