Skip to content

Commit e57bd3c

Browse files
authored
Fix shadow samples in CI (#780)
1 parent c82e731 commit e57bd3c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

samples/shadow/mqtt5_shadow_sync/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ int main(int argc, char *argv[])
311311
std::promise<void> subscribeGetShadowRejectedCompletedPromise;
312312
std::promise<void> onGetShadowRequestCompletedPromise;
313313
std::promise<void> gotInitialShadowPromise;
314+
bool isInitialShadowReceived = false;
314315

315316
auto onGetShadowUpdatedAcceptedSubAck = [&](int ioErr) {
316317
if (ioErr != AWS_OP_SUCCESS)
@@ -347,6 +348,15 @@ int main(int argc, char *argv[])
347348
}
348349
if (response)
349350
{
351+
// If another client requested shadow for the same thing at the same time, this callback might be
352+
// triggered more than once. Ignore everything after first data arrived.
353+
if (isInitialShadowReceived)
354+
{
355+
fprintf(stderr, "Initial shadow is already set, ignore\n");
356+
return;
357+
}
358+
isInitialShadowReceived = true;
359+
350360
fprintf(stdout, "Received shadow document.\n");
351361
if (response->State && response->State->Reported->View().ValueExists(cmdData.input_shadowProperty))
352362
{
@@ -382,6 +392,15 @@ int main(int argc, char *argv[])
382392
fprintf(stderr, "Error on getting shadow document: %s.\n", ErrorDebugString(ioErr));
383393
exit(-1);
384394
}
395+
// If another client requested shadow for the same thing at the same time, this callback might be
396+
// triggered more than once. Ignore everything after first data arrived.
397+
if (isInitialShadowReceived)
398+
{
399+
fprintf(stderr, "Initial shadow is already set, ignore\n");
400+
return;
401+
}
402+
isInitialShadowReceived = true;
403+
385404
fprintf(
386405
stdout,
387406
"Getting shadow document failed with message %s and code %d.\n",

samples/shadow/shadow_sync/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ int main(int argc, char *argv[])
340340
std::promise<void> subscribeGetShadowRejectedCompletedPromise;
341341
std::promise<void> onGetShadowRequestCompletedPromise;
342342
std::promise<void> gotInitialShadowPromise;
343+
bool isInitialShadowReceived = false;
343344

344345
auto onGetShadowUpdatedAcceptedSubAck = [&](int ioErr) {
345346
if (ioErr != AWS_OP_SUCCESS)
@@ -376,6 +377,15 @@ int main(int argc, char *argv[])
376377
}
377378
if (response)
378379
{
380+
// If another client requested shadow for the same thing at the same time, this callback might be
381+
// triggered more than once. Ignore everything after first data arrived.
382+
if (isInitialShadowReceived)
383+
{
384+
fprintf(stderr, "Initial shadow is already set, ignore\n");
385+
return;
386+
}
387+
isInitialShadowReceived = true;
388+
379389
fprintf(stdout, "Received shadow document.\n");
380390
if (response->State && response->State->Reported->View().ValueExists(cmdData.input_shadowProperty))
381391
{
@@ -411,6 +421,15 @@ int main(int argc, char *argv[])
411421
fprintf(stderr, "Error on getting shadow document: %s.\n", ErrorDebugString(ioErr));
412422
exit(-1);
413423
}
424+
// If another client requested shadow for the same thing at the same time, this callback might be
425+
// triggered more than once. Ignore everything after first data arrived.
426+
if (isInitialShadowReceived)
427+
{
428+
fprintf(stderr, "Initial shadow is already set, ignore\n");
429+
return;
430+
}
431+
isInitialShadowReceived = true;
432+
414433
fprintf(
415434
stdout,
416435
"Getting shadow document failed with message %s and code %d.\n",

0 commit comments

Comments
 (0)