Skip to content

Commit 69af717

Browse files
Resolve comments and add e2e tests
1 parent 53abbc4 commit 69af717

File tree

13 files changed

+88
-664
lines changed

13 files changed

+88
-664
lines changed

e2e-tests/fixtures/cluster-setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = async function () {
2424
await waitForChildProcess(cp.exec(`docker update --memory=8g --memory-swap=8g --cpus=4 drasi-test-control-plane`, { encoding: 'utf-8' }));
2525

2626
await Promise.all([
27-
tryLoadInfraImages("drasi-test"),
27+
// tryLoadInfraImages("drasi-test"),
2828
loadDrasiImages("drasi-test")
2929
]);
3030

e2e-tests/fixtures/infrastructure.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const images = [
3939
"drasi-project/reaction-signalr",
4040
"drasi-project/reaction-storedproc",
4141
"drasi-project/reaction-gremlin",
42+
"drasi-project/reaction-post-dapr-pubsub",
4243
];
4344

4445
async function loadDrasiImages(clusterName) {
@@ -106,7 +107,7 @@ async function tryLoadInfraImages(clusterName) {
106107

107108
async function installDrasi() {
108109
await waitForChildProcess(
109-
cp.exec("drasi init --local", {
110+
cp.exec("drasi init --local --version latest", {
110111
encoding: "utf-8",
111112
}),
112113
"install",

reactions/dapr/post-pubsub/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ ENV Logging__LogLevel__Microsoft="Warning"
2828
ENV Logging__LogLevel__Microsoft_Hosting_Lifetime="Information"
2929
ENV Logging__LogLevel__Drasi_Reactions_PostDaprPubSub="Debug"
3030

31-
USER app
3231
ENTRYPOINT ["dotnet", "Drasi.Reactions.PostDaprPubSub.dll"]

reactions/dapr/post-pubsub/Dockerfile.debug

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ ENV Logging__LogLevel__Microsoft="Information"
2929
ENV Logging__LogLevel__Microsoft_Hosting_Lifetime="Information"
3030
ENV Logging__LogLevel__Drasi_Reactions_PostDaprPubSub="Debug"
3131

32-
USER app
3332
ENTRYPOINT ["dotnet", "Drasi.Reactions.PostDaprPubSub.dll"]

reactions/dapr/post-pubsub/Drasi.Reactions.PostDaprPubSub.Tests/ChangeHandlerTests.cs

Lines changed: 6 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,18 @@ public class ChangeHandlerTests
2828
private readonly Mock<DaprClient> _mockDaprClient;
2929
private readonly Mock<IChangeFormatterFactory> _mockFormatterFactory;
3030
private readonly Mock<ILogger<ChangeHandler>> _mockLogger;
31-
private readonly Mock<IQueryFailureTracker> _mockFailureTracker;
3231
private readonly ChangeHandler _handler;
3332

3433
public ChangeHandlerTests()
3534
{
3635
_mockDaprClient = new Mock<DaprClient>();
3736
_mockFormatterFactory = new Mock<IChangeFormatterFactory>();
3837
_mockLogger = new Mock<ILogger<ChangeHandler>>();
39-
_mockFailureTracker = new Mock<IQueryFailureTracker>();
4038

4139
_handler = new ChangeHandler(
4240
_mockDaprClient.Object,
4341
_mockFormatterFactory.Object,
44-
_mockLogger.Object,
45-
_mockFailureTracker.Object
42+
_mockLogger.Object
4643
);
4744
}
4845

@@ -56,22 +53,6 @@ public async Task HandleChange_NullConfig_ThrowsArgumentNullException()
5653
await Assert.ThrowsAsync<ArgumentNullException>(() => _handler.HandleChange(evt, null));
5754
}
5855

59-
[Fact]
60-
public async Task HandleChange_QueryInFailedState_ThrowsInvalidOperationException()
61-
{
62-
// Arrange
63-
var evt = new ChangeEvent { QueryId = "test-query" };
64-
var config = new QueryConfig { PubsubName = "test-pubsub", TopicName = "test-topic" };
65-
66-
_mockFailureTracker.Setup(ft => ft.IsQueryFailed("test-query")).Returns(true);
67-
_mockFailureTracker.Setup(ft => ft.GetFailureReason("test-query")).Returns("Test failure reason");
68-
69-
// Act & Assert
70-
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _handler.HandleChange(evt, config));
71-
Assert.Contains("test-query", ex.Message);
72-
Assert.Contains("Test failure reason", ex.Message);
73-
}
74-
7556
[Fact]
7657
public async Task HandleChange_PackedFormat_PublishesPackedEvent()
7758
{
@@ -83,10 +64,9 @@ public async Task HandleChange_PackedFormat_PublishesPackedEvent()
8364
var config = new QueryConfig {
8465
PubsubName = "test-pubsub",
8566
TopicName = "test-topic",
86-
Packed = true
67+
Format = OutputFormat.Packed
8768
};
8869

89-
_mockFailureTracker.Setup(ft => ft.IsQueryFailed("test-query")).Returns(false);
9070
_mockDaprClient.Setup(dc => dc.PublishEventAsync(
9171
config.PubsubName,
9272
config.TopicName,
@@ -104,8 +84,6 @@ public async Task HandleChange_PackedFormat_PublishesPackedEvent()
10484
It.IsAny<JsonElement>(),
10585
It.IsAny<CancellationToken>()
10686
), Times.Once);
107-
108-
_mockFailureTracker.Verify(ft => ft.ResetFailures("test-query"), Times.Once);
10987
}
11088

11189
[Fact]
@@ -119,7 +97,7 @@ public async Task HandleChange_UnpackedFormat_PublishesUnpackedEvents()
11997
var config = new QueryConfig {
12098
PubsubName = "test-pubsub",
12199
TopicName = "test-topic",
122-
Packed = false // Unpacked is default
100+
Format = OutputFormat.Unpacked
123101
};
124102

125103
var mockFormatter = new Mock<IChangeFormatter>();
@@ -130,7 +108,6 @@ public async Task HandleChange_UnpackedFormat_PublishesUnpackedEvents()
130108
mockFormatter.Setup(f => f.Format(evt)).Returns(formattedElements);
131109
_mockFormatterFactory.Setup(ff => ff.GetFormatter()).Returns(mockFormatter.Object);
132110

133-
_mockFailureTracker.Setup(ft => ft.IsQueryFailed("test-query")).Returns(false);
134111
_mockDaprClient.Setup(dc => dc.PublishEventAsync(
135112
config.PubsubName,
136113
config.TopicName,
@@ -150,85 +127,31 @@ public async Task HandleChange_UnpackedFormat_PublishesUnpackedEvents()
150127
It.IsAny<JsonElement>(),
151128
It.IsAny<CancellationToken>()
152129
), Times.Once);
153-
154-
_mockFailureTracker.Verify(ft => ft.ResetFailures("test-query"), Times.Once);
155130
}
156131

157132
[Fact]
158-
public async Task HandleChange_PublishFails_RecordsFailureAndRethrows()
133+
public async Task HandleChange_PublishFails_ThrowsException()
159134
{
160135
// Arrange
161136
var evt = new ChangeEvent { QueryId = "test-query" };
162137
var config = new QueryConfig {
163138
PubsubName = "test-pubsub",
164139
TopicName = "test-topic",
165-
Packed = true,
166-
MaxFailureCount = 3
140+
Format = OutputFormat.Packed
167141
};
168142

169143
var exception = new DaprException("Test error");
170144

171-
_mockFailureTracker.Setup(ft => ft.IsQueryFailed("test-query")).Returns(false);
172145
_mockDaprClient.Setup(dc => dc.PublishEventAsync(
173146
config.PubsubName,
174147
config.TopicName,
175148
It.IsAny<JsonElement>(),
176149
It.IsAny<CancellationToken>()))
177150
.ThrowsAsync(exception);
178151

179-
_mockFailureTracker.Setup(ft => ft.RecordFailure(
180-
"test-query",
181-
config.MaxFailureCount,
182-
It.IsAny<string>()))
183-
.Returns(false); // Not yet failed
184-
185152
// Act & Assert
186153
var ex = await Assert.ThrowsAsync<DaprException>(() => _handler.HandleChange(evt, config));
187154
Assert.Same(exception, ex);
188-
189-
_mockFailureTracker.Verify(ft => ft.RecordFailure(
190-
"test-query",
191-
config.MaxFailureCount,
192-
It.IsAny<string>()
193-
), Times.Once);
194-
}
195-
196-
[Fact]
197-
public async Task HandleChange_MultipleFailuresExceedingThreshold_MarksQueryAsFailed()
198-
{
199-
// Arrange
200-
var evt = new ChangeEvent { QueryId = "test-query" };
201-
var config = new QueryConfig {
202-
PubsubName = "test-pubsub",
203-
TopicName = "test-topic",
204-
Packed = true,
205-
MaxFailureCount = 3
206-
};
207-
208-
var exception = new DaprException("Test error");
209-
210-
_mockFailureTracker.Setup(ft => ft.IsQueryFailed("test-query")).Returns(false);
211-
_mockDaprClient.Setup(dc => dc.PublishEventAsync(
212-
config.PubsubName,
213-
config.TopicName,
214-
It.IsAny<JsonElement>(),
215-
It.IsAny<CancellationToken>()))
216-
.ThrowsAsync(exception);
217-
218-
_mockFailureTracker.Setup(ft => ft.RecordFailure(
219-
"test-query",
220-
config.MaxFailureCount,
221-
It.IsAny<string>()))
222-
.Returns(true); // Query is now failed
223-
224-
// Act & Assert
225-
await Assert.ThrowsAsync<DaprException>(() => _handler.HandleChange(evt, config));
226-
227-
_mockFailureTracker.Verify(ft => ft.RecordFailure(
228-
"test-query",
229-
config.MaxFailureCount,
230-
It.IsAny<string>()
231-
), Times.Once);
232155
}
233156

234157
[Fact]
@@ -245,7 +168,7 @@ public async Task HandleChange_MultipleUnpackedEvents_PublishesEachEvent()
245168
var config = new QueryConfig {
246169
PubsubName = "test-pubsub",
247170
TopicName = "test-topic",
248-
Packed = false // Unpacked
171+
Format = OutputFormat.Unpacked
249172
};
250173

251174
var mockFormatter = new Mock<IChangeFormatter>();
@@ -257,7 +180,6 @@ public async Task HandleChange_MultipleUnpackedEvents_PublishesEachEvent()
257180
mockFormatter.Setup(f => f.Format(evt)).Returns(formattedElements);
258181
_mockFormatterFactory.Setup(ff => ff.GetFormatter()).Returns(mockFormatter.Object);
259182

260-
_mockFailureTracker.Setup(ft => ft.IsQueryFailed("test-query")).Returns(false);
261183
_mockDaprClient.Setup(dc => dc.PublishEventAsync(
262184
config.PubsubName,
263185
config.TopicName,

0 commit comments

Comments
 (0)