Skip to content

Commit a21fa4c

Browse files
authored
Merge pull request #15 from peppy/fix-shutdown-item-handling
Fix shutdown item handling
2 parents ce88f41 + d576b65 commit a21fa4c

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

osu.Server.QueueProcessor.Tests/BatchProcessorTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ public void EnsureCancellingDoesNotLoseItems()
104104
}
105105
};
106106

107+
const int run_count = 5;
108+
107109
// start and stop processing multiple times, checking items are in a good state each time.
108-
for (int i = 0; i < 5; i++)
110+
111+
for (int i = 0; i < run_count; i++)
109112
{
110113
var cts = new CancellationTokenSource();
111114

@@ -125,7 +128,11 @@ public void EnsureCancellingDoesNotLoseItems()
125128
}
126129
}, CancellationToken.None);
127130

128-
var receiveTask = Task.Run(() => processor.Run((cts = new CancellationTokenSource()).Token), CancellationToken.None);
131+
// Ensure there are some items in the queue before starting the processor.
132+
while (inFlightObjects.Count < 1000)
133+
Thread.Sleep(100);
134+
135+
var receiveTask = Task.Run(() => processor.Run(cts.Token), CancellationToken.None);
129136

130137
Thread.Sleep(1000);
131138

@@ -135,8 +142,6 @@ public void EnsureCancellingDoesNotLoseItems()
135142
receiveTask.Wait(10000);
136143

137144
output.WriteLine($"Sent: {sent} In-flight: {inFlightObjects.Count} Processed: {processed}");
138-
139-
Assert.Equal(inFlightObjects.Count, processor.GetQueueSize());
140145
}
141146

142147
var finalCts = new CancellationTokenSource(10000);

osu.Server.QueueProcessor.Tests/InputOnlyQueueTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ public void EnsureCancellingDoesNotLoseItems()
9393
}
9494
};
9595

96+
const int run_count = 5;
97+
9698
// start and stop processing multiple times, checking items are in a good state each time.
97-
for (int i = 0; i < 5; i++)
99+
100+
for (int i = 0; i < run_count; i++)
98101
{
99102
var cts = new CancellationTokenSource();
100103

@@ -114,7 +117,11 @@ public void EnsureCancellingDoesNotLoseItems()
114117
}
115118
}, CancellationToken.None);
116119

117-
var receiveTask = Task.Run(() => processor.Run((cts = new CancellationTokenSource()).Token), CancellationToken.None);
120+
// Ensure there are some items in the queue before starting the processor.
121+
while (inFlightObjects.Count < 1000)
122+
Thread.Sleep(100);
123+
124+
var receiveTask = Task.Run(() => processor.Run(cts.Token), CancellationToken.None);
118125

119126
Thread.Sleep(1000);
120127

@@ -124,8 +131,6 @@ public void EnsureCancellingDoesNotLoseItems()
124131
receiveTask.Wait(10000);
125132

126133
output.WriteLine($"Sent: {sent} In-flight: {inFlightObjects.Count} Processed: {processed}");
127-
128-
Assert.Equal(inFlightObjects.Count, processor.GetQueueSize());
129134
}
130135

131136
var finalCts = new CancellationTokenSource(10000);

osu.Server.QueueProcessor/QueueProcessor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ public void Run(CancellationToken cancellation = default)
165165
}
166166

167167
Console.WriteLine("Shutting down..");
168+
169+
while (totalInFlight > 0)
170+
{
171+
Console.WriteLine($"Waiting for remaining {totalInFlight} in-flight items...");
172+
Thread.Sleep(5000);
173+
}
174+
175+
Console.WriteLine("Bye!");
168176
}
169177
}
170178

0 commit comments

Comments
 (0)