@@ -27,13 +27,13 @@ class MediatorTest {
27
27
28
28
@Test
29
29
@Timeout(3 , unit = TimeUnit .SECONDS )
30
- fun `call flush twice on two destination plugins` () {
30
+ fun `does work twice on two destination plugins` () {
31
31
val fakeDestinationPlugins = List (2 ) { FakeDestinationPlugin () }
32
32
fakeDestinationPlugins.forEach {
33
33
mediator.add(it)
34
34
}
35
35
36
- // simulate 2 threads executing flush on 2 different DestinationPlugins
36
+ // simulate 2 threads executing work on 2 different DestinationPlugins
37
37
val work = {
38
38
mediator.applyClosure {
39
39
(it as EventPlugin ).flush()
@@ -54,8 +54,8 @@ class MediatorTest {
54
54
}
55
55
56
56
@Test
57
- @Timeout(5 , unit = TimeUnit .SECONDS )
58
- fun `flush , add a new plugin, and flush again on two destination plugins` () {
57
+ @Timeout(7 , unit = TimeUnit .SECONDS )
58
+ fun `work , add a new plugin and work , and work again on two destination plugins` () {
59
59
val fakeDestinationPlugin1 = FakeDestinationPlugin ()
60
60
val fakeDestinationPlugin2 = FakeDestinationPlugin ()
61
61
@@ -67,28 +67,31 @@ class MediatorTest {
67
67
}
68
68
}
69
69
70
- // flush and add
70
+ // work and add, work again
71
71
val latch = CountDownLatch (2 )
72
72
val t1 = thread {
73
+ work()
73
74
work()
74
75
latch.countDown()
75
76
}
76
77
val t2 = thread {
77
- // add plugin 2, work() should catch up with the newly added plugin
78
+ // give time for the first work() to start
79
+ Thread .sleep(100 )
80
+ // add plugin 2, 2nd work() should catch up with the newly added plugin
78
81
mediator.add(fakeDestinationPlugin2)
79
82
latch.countDown()
80
83
}
84
+ t1.join()
85
+ t2.join()
81
86
latch.await()
82
87
83
- // flush again
88
+ // work again
84
89
val t3 = thread {
85
90
work()
86
91
}
87
- t1.join()
88
- t2.join()
89
92
t3.join()
90
93
91
- assertEquals(2 , fakeDestinationPlugin1.amountOfWorkDone.get())
94
+ assertEquals(3 , fakeDestinationPlugin1.amountOfWorkDone.get())
92
95
assertEquals(2 , fakeDestinationPlugin2.amountOfWorkDone.get())
93
96
}
94
97
}
0 commit comments