|
| 1 | +import { sleep } from "@cosmjs/utils"; |
1 | 2 | import { Producer, Stream } from "xstream"; |
2 | 3 |
|
3 | 4 | import { concat } from "./concat"; |
4 | 5 |
|
5 | 6 | async function producerIsStopped(): Promise<void> { |
6 | | - return new Promise((resolve) => setTimeout(resolve, 50)); |
| 7 | + return sleep(50); |
7 | 8 | } |
8 | 9 |
|
9 | 10 | describe("concat", () => { |
@@ -250,41 +251,41 @@ describe("concat", () => { |
250 | 251 |
|
251 | 252 | expect(producerActiveLog).toEqual([true]); |
252 | 253 |
|
| 254 | + await sleep(3.75 * intervalDuration); |
| 255 | + |
253 | 256 | // unsubscribe |
254 | | - setTimeout(async () => { |
255 | | - expect(producerActiveLog).toEqual([true]); |
256 | | - subscription.unsubscribe(); |
257 | | - await producerIsStopped(); |
258 | | - expect(producerActiveLog).toEqual([true, false]); |
259 | | - }, 3.75 * intervalDuration); |
| 257 | + expect(producerActiveLog).toEqual([true]); |
| 258 | + subscription.unsubscribe(); |
| 259 | + await producerIsStopped(); |
| 260 | + expect(producerActiveLog).toEqual([true, false]); |
| 261 | + |
| 262 | + await sleep(2.2 * intervalDuration); |
260 | 263 |
|
261 | 264 | // re-subscribe |
262 | | - setTimeout(() => { |
263 | | - expect(producerActiveLog).toEqual([true, false]); |
264 | | - |
265 | | - const subscription2 = concatenatedStream.subscribe({ |
266 | | - next: (value) => { |
267 | | - expect(value).toEqual(expected.shift()!); |
268 | | - }, |
269 | | - complete: () => { |
270 | | - done.fail(); |
271 | | - }, |
272 | | - error: done.fail, |
273 | | - }); |
274 | | - |
275 | | - expect(producerActiveLog).toEqual([true, false, true]); |
276 | | - |
277 | | - // unsubscribe again |
278 | | - setTimeout(async () => { |
279 | | - expect(producerActiveLog).toEqual([true, false, true]); |
280 | | - subscription2.unsubscribe(); |
281 | | - await producerIsStopped(); |
282 | | - expect(producerActiveLog).toEqual([true, false, true, false]); |
| 265 | + expect(producerActiveLog).toEqual([true, false]); |
283 | 266 |
|
284 | | - expect(expected.length).toEqual(0); |
285 | | - done(); |
286 | | - }, 3.75 * intervalDuration); |
287 | | - }, 6 * intervalDuration); |
| 267 | + const subscription2 = concatenatedStream.subscribe({ |
| 268 | + next: (value) => { |
| 269 | + expect(value).toEqual(expected.shift()!); |
| 270 | + }, |
| 271 | + complete: () => { |
| 272 | + done.fail(); |
| 273 | + }, |
| 274 | + error: done.fail, |
| 275 | + }); |
| 276 | + |
| 277 | + expect(producerActiveLog).toEqual([true, false, true]); |
| 278 | + |
| 279 | + await sleep(3.75 * intervalDuration); |
| 280 | + |
| 281 | + // unsubscribe again |
| 282 | + expect(producerActiveLog).toEqual([true, false, true]); |
| 283 | + subscription2.unsubscribe(); |
| 284 | + await producerIsStopped(); |
| 285 | + expect(producerActiveLog).toEqual([true, false, true, false]); |
| 286 | + |
| 287 | + expect(expected.length).toEqual(0); |
| 288 | + done(); |
288 | 289 |
|
289 | 290 | return ret; |
290 | 291 | }); |
|
0 commit comments