Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions n_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,22 +528,12 @@ J *_noteTransactionShouldLock(J *req, bool lockNotecard)
_LockNote();
}

// If a reset of the I/O interface is required for any reason, do it now.
// If a reset of the I/O interface is required for any reason, make a best
// effort to resynchronize before continuing with the transaction.
if (resetRequired) {
NOTE_C_LOG_DEBUG("Resetting Notecard I/O Interface...");
if ((resetRequired = !_Reset())) {
if (lockNotecard) {
_UnlockNote();
}
_Free(json);
_TransactionStop();
const char *errStr = ERRSTR("failed to reset Notecard interface {io}", c_iobad);
if (cmdFound) {
NOTE_C_LOG_ERROR(errStr);
return NULL;
}
return _errDoc(id, errStr);
}
_Reset();
resetRequired = false;
}

// If we're performing retries, this is where we come back to
Expand Down
23 changes: 13 additions & 10 deletions test/src/NoteTransaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ SCENARIO("NoteTransaction")
JDelete(req);
}

SECTION("A reset is required and it fails") {
SECTION("A reset is required and it fails before a command") {
J *req = NoteNewCommand("note.add");
REQUIRE(req != NULL);
NoteResetRequired();
Expand All @@ -515,31 +515,34 @@ SCENARIO("NoteTransaction")
J *resp = NoteTransaction(req);
REQUIRE(_noteHardReset_fake.call_count == 1);

// The transaction shouldn't be attempted if reset failed.
CHECK(_noteJSONTransaction_fake.call_count == 0);
// Reset is best effort; the transaction is still attempted.
CHECK(_noteJSONTransaction_fake.call_count == 1);
CHECK(resetRequired == false);

// The response should be null if reset failed.
CHECK(resp == NULL);
// Commands return an empty response object after the transaction attempt.
CHECK(resp != NULL);

JDelete(req);
JDelete(resp);
}

SECTION("A reset is required and it fails") {
SECTION("A reset is required and it fails before a request") {
J *req = NoteNewRequest("note.add");
REQUIRE(req != NULL);
NoteResetRequired();
// Force NoteReset failure.
_noteHardReset_fake.return_val = false;
_noteJSONTransaction_fake.custom_fake = _noteJSONTransactionValid;

J *resp = NoteTransaction(req);
REQUIRE(_noteHardReset_fake.call_count == 1);

// The transaction shouldn't be attempted if reset failed.
CHECK(_noteJSONTransaction_fake.call_count == 0);
// Reset is best effort; the transaction is still attempted.
CHECK(_noteJSONTransaction_fake.call_count == 1);
CHECK(resetRequired == false);

// The response should be null if reset failed.
CHECK(resp != NULL);
CHECK(NoteResponseError(resp));
CHECK(!NoteResponseError(resp));

JDelete(req);
JDelete(resp);
Expand Down
Loading