8000 Add more tests · localstack/localstack@399b60d · GitHub
[go: up one dir, main page]

Skip to content

Commit 399b60d

Browse files
committed
Add more tests
1 parent 6ed957b commit 399b60d

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

localstack-core/localstack/utils/batch_policy.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ class Batcher(Generic[T]):
2929
3030
# Triggers when 2 (or more) items are added
3131
batcher = Batcher(max_count=2)
32-
assert batcher.add(["foo", "bar", "baz"])
33-
assert batcher.flush() == ["foo", "bar", "baz"]
32+
assert batcher.add(["item1", "item2", "item3"])
33+
assert batcher.flush() == ["item1", "item2", "item3"]
3434
3535
# Triggers partially when 2 (or more) items are added
3636
batcher = Batcher(max_count=2)
37-
assert batcher.add(["foo", "bar", "baz"])
38-
assert batcher.flush(partial=True) == ["foo", "bar"]
39-
assert batcher.add("foobar")
40-
assert batcher.flush(partial=True) == ["baz", "foobar"]
37+
assert batcher.add(["item1", "item2", "item3"])
38+
assert batcher.flush(partial=True) == ["item1", "item2"]
39+
assert batcher.add("item4")
40+
assert batcher.flush(partial=True) == ["item3", "item4"]
4141
4242
# Trigger 2 seconds after the first add
4343
batcher = Batcher(max_window=2.0)
44-
assert not batcher.add(["foo", "bar", "baz"])
44+
assert not batcher.add(["item1", "item2", "item3"])
4545
time.sleep(2.1)
46-
assert not batcher.add(["foobar"])
47-
assert batcher.flush() == ["foo", "bar", "baz", "foobar"]
46+
assert not batcher.add(["item4"])
47+
assert batcher.flush() == ["item1", "item2", "item3", "item4"]
4848
"""
4949

5050
max_count: Optional[int] = Field(default=None, description="Maximum number of items", ge=0)
@@ -108,6 +108,7 @@ def flush(self, *, partial=False) -> list[T]:
108108

109109
self._last_batch_time = time.monotonic()
110110
self._triggered = False
111+
self._check_batch_policy()
111112

112113
return result
113114

tests/unit/utils/test_batch_policy.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import time
22

3+
import pytest
4+
35
from localstack.utils.batch_policy import Batcher
46

57

@@ -122,8 +124,16 @@ def test_flush(self):
122124
assert result == ["item4"]
123125
assert batcher.get_current_size() == 0
124126

125-
def test_no_limits(self):
126-
batcher = Batcher()
127+
@pytest.mark.parametrize(
128+
"max_count,max_window",
129+
[(0, 10), (10, 0), (None, None)],
130+
)
131+
def test_no_limits(self, max_count, max_window):
132+
if max_count or max_window:
133+
batcher = Batcher(max_count=max_count, max_window=max_window)
134+
else:
135+
batcher = Batcher()
136+
127137
assert batcher.is_triggered() # no limit always returns true
128138

129139
assert batcher.add("item1")
@@ -172,7 +182,7 @@ def test_deep_copy(self):
172182
original = {"key": "value"}
173183
batcher = Batcher(max_count=2)
174184

175-
batcher.add(original, cache_deep_copy=True)
185+
batcher.add(original, deep_copy=True)
176186

177187
original["key"] = "modified"
178188

0 commit comments

Comments
 (0)
0