Skip to content

Commit 0747884

Browse files
authored
Merge pull request #423 from Danielle9897/RDBC-832-fixDeleteCmpXchg
RDBC-832 Fix DeleteCompareExchangeValueOperation behavior when key doesn't exist
2 parents 36790be + 66dc85e commit 0747884

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Documents/Operations/CompareExchange/CompareExchangeResult.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CompareExchangeResult<T> {
2727
throwError("InvalidOperationException", "Response is invalid. Index is missing");
2828
}
2929

30-
const val = response.Value.Object || null;
30+
const val = response.Value?.Object || null;
3131
return CompareExchangeResult._create(val, response.Index, response.Successful, conventions, clazz);
3232
}
3333

test/Ported/UniqueValuesTest.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,35 @@ describe("UniqueValuesTest", function () {
156156
assert.strictEqual(readValue.value, "Karmel");
157157
});
158158

159+
it("tryingToDeleteNonExistingKeyShouldNotThrow", async () => {
160+
const res1= await store.operations.send(
161+
new PutCompareExchangeValueOperation<string>("key/1", "Name", 0));
162+
163+
assert.strictEqual(res1.value, "Name");
164+
assert.ok(res1.successful);
165+
166+
const res2 = await store.operations.send(
167+
new DeleteCompareExchangeValueOperation<string>("key/2", res1.index));
168+
169+
assert.ok(res2.successful);
170+
assert.equal(res2.value, null);
171+
assert.equal(res2.index, res1.index + 1);
172+
173+
const res3 = await store.operations.send(
174+
new DeleteCompareExchangeValueOperation<string>("key/2", 0));
175+
176+
assert.ok(res3.successful);
177+
assert.equal(res3.value, null);
178+
assert.equal(res3.index, res2.index + 1);
179+
180+
const res4 = await store.operations.send(
181+
new DeleteCompareExchangeValueOperation<string>("key/2", 999));
182+
183+
assert.ok(res4.successful);
184+
assert.equal(res4.value, null);
185+
assert.equal(res4.index, res3.index + 1);
186+
});
187+
159188
it("returnCurrentValueWhenPuttingConcurrently", async () => {
160189
const user = new User();
161190
user.name = "Karmel";

0 commit comments

Comments
 (0)