3
3
from river import models
4
4
from river .adapters .progression_counter import InMemoryProgressionCounter
5
5
from river .adapters .topics import InMemoryTopicsManager
6
- from river .topicleaner .service import clean
6
+ from river .topicleaner .service import task as topicleaner_task
7
7
8
8
pytestmark = pytest .mark .django_db
9
9
10
10
11
- def test_done_batch_is_cleaned (batch_factory , resource_factory ):
11
+ def test_done_batch_is_cleaned (resource_factory , batch_factory , progression_factory ):
12
12
r1 , r2 = resource_factory .create_batch (2 )
13
13
batch = batch_factory .create (resources = [r1 , r2 ])
14
+ progression_factory .create (batch = batch , resource = r1 )
15
+ progression_factory .create (batch = batch , resource = r2 )
14
16
counters = InMemoryProgressionCounter (
15
17
counts = {f"{ batch .id } :{ resource .id } " : {"extracted" : 10 , "loaded" : 10 } for resource in batch .resources .all ()}
16
18
)
17
19
topics = InMemoryTopicsManager (
18
20
topics = [f"{ base_topic } .{ batch .id } " for base_topic in ["batch" , "extract" , "transform" , "load" ]]
19
21
)
20
22
21
- clean (counters , topics )
23
+ topicleaner_task (counters , topics )
22
24
23
25
assert topics ._topics == set ()
24
26
batches = models .Batch .objects .all ()
@@ -30,9 +32,11 @@ def test_done_batch_is_cleaned(batch_factory, resource_factory):
30
32
assert progression .failed is None
31
33
32
34
33
- def test_done_batch_is_cleaned_with_failed (batch_factory , resource_factory ):
35
+ def test_done_batch_is_cleaned_with_failed (resource_factory , batch_factory , progression_factory ):
34
36
r1 , r2 = resource_factory .create_batch (2 )
35
37
batch = batch_factory .create (resources = [r1 , r2 ])
38
+ progression_factory .create (batch = batch , resource = r1 )
39
+ progression_factory .create (batch = batch , resource = r2 )
36
40
counters = InMemoryProgressionCounter (
37
41
counts = {
38
42
f"{ batch .id } :{ resource .id } " : {"extracted" : 10 , "loaded" : 6 , "failed" : 4 }
@@ -42,7 +46,7 @@ def test_done_batch_is_cleaned_with_failed(batch_factory, resource_factory):
42
46
topics = InMemoryTopicsManager (
43
47
topics = [f"{ base_topic } .{ batch .id } " for base_topic in ["batch" , "extract" , "transform" , "load" ]]
44
48
)
45
- clean (counters , topics )
49
+ topicleaner_task (counters , topics )
46
50
47
51
assert topics ._topics == set ()
48
52
batches = models .Batch .objects .all ()
@@ -64,7 +68,7 @@ def test_ongoing_batch_is_not_cleaned(batch_factory, resource_factory):
64
68
topics = [f"{ base_topic } .{ batch .id } " for base_topic in ["batch" , "extract" , "transform" , "load" ]]
65
69
)
66
70
67
- clean (counters , topics )
71
+ topicleaner_task (counters , topics )
68
72
69
73
assert topics ._topics != set ()
70
74
@@ -82,7 +86,7 @@ def test_ongoing_batch_is_not_cleaned_with_failed(batch_factory, resource_factor
82
86
topics = [f"{ base_topic } .{ batch .id } " for base_topic in ["batch" , "extract" , "transform" , "load" ]]
83
87
)
84
88
85
- clean (counters , topics )
89
+ topicleaner_task (counters , topics )
86
90
87
91
assert topics ._topics != set ()
88
92
@@ -97,7 +101,7 @@ def test_none_counter_prevents_cleaning(batch_factory, resource_factory):
97
101
topics = [f"{ base_topic } .{ batch .id } " for base_topic in ["batch" , "extract" , "transform" , "load" ]]
98
102
)
99
103
100
- clean (counters , topics )
104
+ topicleaner_task (counters , topics )
101
105
102
106
assert topics ._topics != set ()
103
107
@@ -112,6 +116,6 @@ def test_missing_counter_prevents_cleaning(batch_factory, resource_factory):
112
116
topics = [f"{ base_topic } .{ batch .id } " for base_topic in ["batch" , "extract" , "transform" , "load" ]]
113
117
)
114
118
115
- clean (counters , topics )
119
+ topicleaner_task (counters , topics )
116
120
117
121
assert topics ._topics != set ()
0 commit comments