forked from Azure/iotedge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E: Add regression test for custom mqtt topics (Azure#4857)
This PR is adding an E2E test for custom mqtt topics using the existing ```genericMqttTester``` image we run in longhaul. This test will deploy edgehub with the broker enabled and two genericMqttTester modules. One genericMqttTester module will be in initiate mode and the other will be in relay mode. The initiate mode module will publish on an mqtt topic ```initiate/1``` and the relaying module will subscribe to this topic. When the relaying module receives a message, it will publish it back on ```relay/1```. The initiating module will be subscribed on this ```relay/1``` topic and will report to the TRC when it receives the message. In addition to adding the test it: 1. Refactors shared logic into util abstractions for cleaner code. Specifically adding the broker/TRC to the deployment. 2. Introduces a configuration for defining the restartPolicy for test module deployed in the test. This is done so that the genericMqttTester module will no start back up after it sends its defined amount of messages. 3. Improves the genericMqttTester module to use the module name when reporting to the trc rather than some hardcoded string "genericMqttTester". This allows the dotnet test code we right here to be more understandable. 3. Updates the documentation to include new parameters required for this test
- Loading branch information
1 parent
2b8d49f
commit c7053ab
Showing
16 changed files
with
381 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Test | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Devices.Edge.Test.Common; | ||
using Microsoft.Azure.Devices.Edge.Test.Common.Config; | ||
using Microsoft.Azure.Devices.Edge.Test.Helpers; | ||
using Microsoft.Azure.Devices.Edge.Util.Test.Common.NUnit; | ||
using NUnit.Framework; | ||
|
||
[EndToEnd] | ||
public class GenericMqtt : SasManualProvisioningFixture | ||
{ | ||
const string NetworkControllerModuleName = "networkController"; | ||
const string GenericMqttInitiatorModuleName = "GenericMqttInitiator"; | ||
const string GenericMqttRelayerModuleName = "GenericMqttRelayer"; | ||
const string GenericMqttTesterMaxMessages = "5"; | ||
const string GenericMqttTesterTestStartDelay = "10s"; | ||
const int SecondsBeforeVerification = 45; | ||
|
||
/// <summary> | ||
/// Scenario: | ||
/// - Deploy Edge Hub with the broker enabled and two genericMqttTester | ||
/// modules. | ||
/// - One genericMqttTester module will be in initiate mode and the other | ||
/// will be in relay mode. | ||
/// - The initiate mode module will publish on an mqtt topic initiate/1 | ||
/// which the relaying module will be subscribed to. | ||
/// - When the relaying module receives a message, it will publish it | ||
/// back on relay/1. | ||
/// - The initiating module will be subscribed on this relay/1 topic | ||
/// and will report to the TRC when it receives the message. | ||
/// </summary> | ||
/// <returns><see cref="Task"/> representing the asynchronous unit test.</returns> | ||
[Test] | ||
public async Task GenericMqttTelemetry() | ||
{ | ||
CancellationToken token = this.TestToken; | ||
string networkControllerImage = Context.Current.NetworkControllerImage.Expect(() => new ArgumentException("networkControllerImage parameter is required for Generic Mqtt test")); | ||
string trcImage = Context.Current.TestResultCoordinatorImage.Expect(() => new ArgumentException("testResultCoordinatorImage parameter is required for Generic Mqtt test")); | ||
string genericMqttTesterImage = Context.Current.GenericMqttTesterImage.Expect(() => new ArgumentException("genericMqttTesterImage parameter is required for Generic Mqtt test")); | ||
string trackingId = Guid.NewGuid().ToString(); | ||
|
||
Action<EdgeConfigBuilder> addMqttBrokerConfig = MqttBrokerUtil.BuildAddBrokerToDeployment(false); | ||
Action<EdgeConfigBuilder> addNetworkControllerConfig = TestResultCoordinatorUtil.BuildAddNetworkControllerConfig(trackingId, networkControllerImage); | ||
Action<EdgeConfigBuilder> addTestResultCoordinatorConfig = TestResultCoordinatorUtil.BuildAddTestResultCoordinatorConfig(trackingId, trcImage, GenericMqttInitiatorModuleName, GenericMqttInitiatorModuleName); | ||
Action<EdgeConfigBuilder> addGenericMqttTesterConfig = this.BuildAddGenericMqttTesterConfig(trackingId, trcImage, genericMqttTesterImage); | ||
Action<EdgeConfigBuilder> config = addMqttBrokerConfig + addNetworkControllerConfig + addTestResultCoordinatorConfig + addGenericMqttTesterConfig; | ||
EdgeDeployment deployment = await this.runtime.DeployConfigurationAsync(config, token, Context.Current.NestedEdge); | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(SecondsBeforeVerification)); | ||
|
||
await TestResultCoordinatorUtil.ValidateResultsAsync(); | ||
} | ||
|
||
private Action<EdgeConfigBuilder> BuildAddGenericMqttTesterConfig(string trackingId, string trcImage, string genericMqttTesterImage) | ||
{ | ||
return new Action<EdgeConfigBuilder>( | ||
builder => | ||
{ | ||
builder.AddModule(GenericMqttInitiatorModuleName, genericMqttTesterImage, false) | ||
.WithEnvironment(new[] | ||
{ | ||
("TEST_SCENARIO", "Initiate"), | ||
("TRACKING_ID", trackingId), | ||
("TEST_START_DELAY", GenericMqttTesterTestStartDelay), | ||
("MESSAGES_TO_SEND", GenericMqttTesterMaxMessages), | ||
}); | ||
|
||
builder.AddModule(GenericMqttRelayerModuleName, genericMqttTesterImage, false) | ||
.WithEnvironment(new[] | ||
{ | ||
("TEST_SCENARIO", "Relay"), | ||
("TRACKING_ID", trackingId), | ||
("TEST_START_DELAY", GenericMqttTesterTestStartDelay), | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.