Skip to content

Commit 099e39f

Browse files
authored
fix a bad timestamp value in a test which caused it to fail sometimes due to retention (#412)
fixes #410, fixes #390 fixes bad timestamp values in app groupby tests
1 parent badc591 commit 099e39f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/test_quixstreams/test_app.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def on_message_processed(*_):
557557

558558
processed_count = 0
559559

560-
timestamp = 1000
560+
timestamp_ms = int(time.time() * 1000)
561561
user_id = "abc123"
562562
value_in = {"user": user_id}
563563
expected_message_count = 1
@@ -589,7 +589,7 @@ def on_message_processed(*_):
589589

590590
with app.get_producer() as producer:
591591
msg = app_topic_in.serialize(
592-
key="some_key", value=value_in, timestamp_ms=timestamp
592+
key="some_key", value=value_in, timestamp_ms=timestamp_ms
593593
)
594594
producer.produce(
595595
app_topic_in.name, key=msg.key, value=msg.value, timestamp=msg.timestamp
@@ -615,7 +615,7 @@ def on_message_processed(*_):
615615
# as original one
616616
assert row.value == {
617617
"user": user_id,
618-
"groupby_timestamp": timestamp,
618+
"groupby_timestamp": timestamp_ms,
619619
}
620620

621621
@pytest.mark.parametrize("processing_guarantee", ["exactly-once", "at-least-once"])
@@ -643,7 +643,10 @@ def on_message_processed(*_):
643643

644644
processed_count = 0
645645

646-
timestamp = 1000
646+
window_duration_ms = 1000
647+
timestamp_ms = int(time.time() * 1000)
648+
# use a "window-friendly" timestamp for easier testing
649+
timestamp_ms = timestamp_ms - (timestamp_ms % window_duration_ms)
647650
user_id = "abc123"
648651
value_in = {"user": user_id}
649652
expected_message_count = 1
@@ -672,12 +675,12 @@ def on_message_processed(*_):
672675
sdf["groupby_timestamp"] = sdf.apply(
673676
lambda value, key, timestamp_, headers: timestamp_, metadata=True
674677
)
675-
sdf = sdf.tumbling_window(duration_ms=1000).count().current()
678+
sdf = sdf.tumbling_window(duration_ms=window_duration_ms).count().current()
676679
sdf = sdf.to_topic(app_topic_out)
677680

678681
with app.get_producer() as producer:
679682
msg = app_topic_in.serialize(
680-
key="some_key", value=value_in, timestamp_ms=timestamp
683+
key="some_key", value=value_in, timestamp_ms=timestamp_ms
681684
)
682685
producer.produce(
683686
app_topic_in.name, key=msg.key, value=msg.value, timestamp=msg.timestamp
@@ -700,7 +703,11 @@ def on_message_processed(*_):
700703
# Check that "user_id" is now used as a message key
701704
assert row.key.decode() == user_id
702705
# Check that window is calculated based on the original timestamp
703-
assert row.value == {"start": 1000, "end": 2000, "value": 1}
706+
assert row.value == {
707+
"start": timestamp_ms,
708+
"end": timestamp_ms + window_duration_ms,
709+
"value": 1,
710+
}
704711

705712

706713
class TestAppExactlyOnce:

0 commit comments

Comments
 (0)