-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathtest_nowstream.py
More file actions
58 lines (47 loc) · 1.6 KB
/
test_nowstream.py
File metadata and controls
58 lines (47 loc) · 1.6 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
import unittest
import time
from feldera.pipeline_builder import PipelineBuilder
from feldera.runtime_config import RuntimeConfig
from feldera.testutils import (
unique_pipeline_name,
FELDERA_TEST_NUM_WORKERS,
FELDERA_TEST_NUM_HOSTS,
)
from tests import TEST_CLIENT
from feldera.enums import PipelineStatus
def get_result(pipeline) -> str:
result = list(pipeline.query("SELECT * FROM v;"))
assert len(result) == 1
return result[0]["x"]
class TestNowStream(unittest.TestCase):
def test_nowstream(self):
"""
Test the now() function:
pipeline should produce outputs even if no new inputs are supplied.
"""
pipeline_name = unique_pipeline_name("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
time0 = get_result(pipeline)
time.sleep(1)
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()