-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathtest_nowstream.py
More file actions
62 lines (51 loc) · 1.81 KB
/
Copy pathtest_nowstream.py
File metadata and controls
62 lines (51 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import unittest
import time
from feldera.pipeline_builder import PipelineBuilder
from feldera.runtime_config import RuntimeConfig
from feldera.testutils import (
FELDERA_TEST_NUM_WORKERS,
FELDERA_TEST_NUM_HOSTS,
)
from tests import TEST_CLIENT
from tests.platform.helper import PipelineTestCase
from feldera.enums import PipelineStatus
def get_result(pipeline) -> str:
result = list(pipeline.query("SELECT * FROM v;"))
assert len(result) == 1, f"result length was not 1; result: {result}"
assert "x" in result[0], (
f"first entry of result did not contain column 'x'; result: {result}"
)
return result[0]["x"]
class TestNowStream(PipelineTestCase):
def test_nowstream(self):
"""
Test the now() function:
pipeline should produce outputs even if no new inputs are supplied.
"""
pipeline_name = self.register_for_cleanup("test_now")
sql = """
CREATE MATERIALIZED VIEW v AS SELECT NOW() as X;
"""
pipeline = PipelineBuilder(
TEST_CLIENT,
pipeline_name,
sql=sql,
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
# 10 times per second
clock_resolution_usecs=100000,
),
).create_or_replace()
pipeline.start()
assert pipeline.status() == PipelineStatus.RUNNING
time.sleep(2)
time0 = get_result(pipeline)
time.sleep(2)
time1 = get_result(pipeline)
# Time has increased; this works on string time representations too
# due to the standard format, which looks like `2025-10-20T20:55:16.350`
assert time1 > time0
pipeline.stop(force=True)
if __name__ == "__main__":
unittest.main()