Skip to content

Commit

Permalink
Fixing twin tests for connectivity (Azure#2631)
Browse files Browse the repository at this point in the history
We are seeing a bug in Connectivity Twin Tests. 

When we start the tests, we do a cleanup - where we grab the current twin, set its properties to null, and send an UpdateReportedProperties call. Due to how the SDK works, this will automatically subscribe us for receiving DesiredPropertiesUpdates (DPU). But then we wait for 2 minutes due to the testStartDelay. After that, we set the callback for receiving DPUs.

The issue is that if we receive a DPU during the testStartDelay, the callback won't be set, and we will do nothing. 

So this PR moves the callback up before the testStartDelay, so that we are ready to receive even during the waiting period. 

It also removes the cleanup because it is unnecessary now that we are using a fresh device every time.
  • Loading branch information
dylanbronson authored Mar 4, 2020
1 parent ab94364 commit 1b106ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
1 change: 1 addition & 0 deletions test/modules/TwinTester/DesiredPropertyReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public DesiredPropertyReceiver(ModuleClient moduleClient, ITwinTestResultHandler

public Task UpdateAsync()
{
Logger.LogInformation("Setting desired property update callback");
return this.moduleClient.SetDesiredPropertyUpdateCallbackAsync(this.OnDesiredPropertyUpdateAsync, null);
}

Expand Down
8 changes: 2 additions & 6 deletions test/modules/TwinTester/TwinCloudOperationsInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ public static async Task<TwinCloudOperationsInitializer> CreateAsync(RegistryMan
TwinState initializedState;
Twin twin = await registryManager.GetTwinAsync(Settings.Current.DeviceId, Settings.Current.TargetModuleId);

// reset desired properties
twin.Properties.Desired = null;
Twin desiredPropertyResetTwin = await registryManager.ReplaceTwinAsync(Settings.Current.DeviceId, Settings.Current.TargetModuleId, twin, twin.ETag);
initializedState = new TwinState { TwinETag = twin.ETag };

initializedState = new TwinState { TwinETag = desiredPropertyResetTwin.ETag };

Logger.LogInformation($"Start state of module twin: {JsonConvert.SerializeObject(desiredPropertyResetTwin, Formatting.Indented)}");
Logger.LogInformation($"Start state of module twin: {JsonConvert.SerializeObject(twin, Formatting.Indented)}");
return new TwinCloudOperationsInitializer(registryManager, resultHandler, initializedState);
}
catch (Exception e)
Expand Down
17 changes: 3 additions & 14 deletions test/modules/TwinTester/TwinEdgeOperationsInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,18 @@ class TwinEdgeOperationsInitializer : ITwinTestInitializer
this.desiredPropertiesReceiver = new DesiredPropertyReceiver(moduleClient, reporter);
}

public static async Task<TwinEdgeOperationsInitializer> CreateAsync(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler reporter)
public static Task<TwinEdgeOperationsInitializer> CreateAsync(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler reporter)
{
try
{
Twin twin = await registryManager.GetTwinAsync(Settings.Current.DeviceId, Settings.Current.TargetModuleId);

// reset reported properties
await TwinTesterUtil.ResetTwinReportedPropertiesAsync(moduleClient, twin);
return new TwinEdgeOperationsInitializer(registryManager, moduleClient, reporter, 0);
}
catch (Exception e)
{
throw new Exception($"Shutting down module. Initialization failure: {e}");
}
return Task.FromResult(new TwinEdgeOperationsInitializer(registryManager, moduleClient, reporter, 0));
}

public async Task StartAsync(CancellationToken cancellationToken)
{
await this.desiredPropertiesReceiver.UpdateAsync();
Logger.LogInformation($"Waiting for {Settings.Current.TestStartDelay} based on TestStartDelay setting before starting.");
await Task.Delay(Settings.Current.TestStartDelay, cancellationToken);
await this.LogEdgeDeviceTwin();
this.periodicUpdate = new PeriodicTask(this.UpdateAsync, Settings.Current.TwinUpdateFrequency, Settings.Current.TwinUpdateFrequency, Logger, "TwinReportedPropertiesUpdate");
await this.desiredPropertiesReceiver.UpdateAsync();
}

async Task LogEdgeDeviceTwin()
Expand Down

0 comments on commit 1b106ec

Please sign in to comment.