Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race conditions in samples and service tests #748

Merged
merged 5 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion samples/fleet_provisioning/fleet_provisioning/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ int main(int argc, char *argv[])
{
/************************ Setup ****************************/

// Do the global initialization for the API
// Do the global initialization for the API
ApiHandle apiHandle;

/**
Expand Down
6 changes: 3 additions & 3 deletions samples/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct RegisterThingContext
/**
* Create MQTT5 client.
*/
std::shared_ptr<Aws::Crt::Mqtt5::Mqtt5Client> createMqtt5Client(Mqtt5ClientContext &ctx, const Utils::cmdData &cmdData)
std::shared_ptr<Aws::Crt::Mqtt5::Mqtt5Client> createMqtt5Client(const Utils::cmdData &cmdData, Mqtt5ClientContext &ctx)
{
// Create the MQTT5 builder and populate it with data from cmdData.
Aws::Iot::Mqtt5ClientBuilder *builder = Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
Expand Down Expand Up @@ -418,7 +418,7 @@ int main(int argc, char *argv[])
{
/************************ Setup ****************************/

// Do the global initialization for the API
// Do the global initialization for the API
ApiHandle apiHandle;

/**
Expand All @@ -429,7 +429,7 @@ int main(int argc, char *argv[])
Utils::cmdData cmdData = Utils::parseSampleInputFleetProvisioning(argc, argv, &apiHandle);

Mqtt5ClientContext mqtt5ClientContext;
auto client = createMqtt5Client(mqtt5ClientContext, cmdData);
auto client = createMqtt5Client(cmdData, mqtt5ClientContext);

/************************ Run the sample ****************************/

Expand Down
4 changes: 4 additions & 0 deletions samples/secure_tunneling/secure_tunnel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ int main(int argc, char *argv[])
* In a real world application you probably don't want to enforce synchronous behavior
* but this is a sample console application, so we'll just do that with a condition variable.
*/
std::promise<void> clientConnectedPromise;
std::promise<bool> clientStoppedPromise;

// service id storage for use in sample
Expand Down Expand Up @@ -285,6 +286,7 @@ int main(int argc, char *argv[])
fprintf(stdout, "Sending Stream Start request\n");
secureTunnel->SendStreamStart();
}
clientConnectedPromise.set_value();
}
});

Expand Down Expand Up @@ -345,6 +347,8 @@ int main(int argc, char *argv[])
exit(-1);
}

clientConnectedPromise.get_future().wait_for(std::chrono::seconds(5));

/*
* In Destination mode the Secure Tunnel Client will remain open and echo messages that come in.
* In Source mode the Secure Tunnel Client will send 4 messages and then disconnect and terminate.
Expand Down
Loading
Loading