Skip to content

Commit

Permalink
Fixing test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewc committed Oct 6, 2015
1 parent 53337ce commit 1ab4ee5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public void Trigger_ViaIBinder_CannotBind()
queue.AddMessage(message);

// Act
Exception expection = RunTriggerFailure<string>(account, typeof(BindToQueueTriggerViaIBinderProgram),
Exception exception = RunTriggerFailure<string>(account, typeof(BindToQueueTriggerViaIBinderProgram),
(s) => BindToQueueTriggerViaIBinderProgram.TaskSource = s);

// Assert
Assert.Equal("No binding found for attribute 'Microsoft.Azure.WebJobs.QueueTriggerAttribute'.",
expection.Message);
Assert.Equal("Exception while executing function: BindToQueueTriggerViaIBinderProgram.Run", exception.Message);
Assert.Equal("No binding found for attribute 'Microsoft.Azure.WebJobs.QueueTriggerAttribute'.", exception.InnerException.Message);
}

private static IStorageAccount CreateFakeStorageAccount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ public static Exception RunTriggerFailure(IStorageAccount account, Type programT
}

Assert.Equal(TaskStatus.RanToCompletion, task.Status);
return task.Result;
Exception exception = task.Result;
Assert.IsType<FunctionInvocationException>(exception);
return exception.InnerException;
}
}

Expand All @@ -395,8 +397,7 @@ public static Exception RunTriggerFailure<TResult>(IStorageAccount account, Type
{
// Arrange
TaskCompletionSource<Exception> failureTaskSource = new TaskCompletionSource<Exception>();
IServiceProvider serviceProvider = CreateServiceProviderForInstanceFailure(account, programType,
failureTaskSource);
IServiceProvider serviceProvider = CreateServiceProviderForInstanceFailure(account, programType, failureTaskSource);
TaskCompletionSource<TResult> successTaskSource = new TaskCompletionSource<TResult>();
// The task for failed function invocation (should complete successfully with an exception).
Task<Exception> failureTask = failureTaskSource.Task;
Expand Down Expand Up @@ -432,7 +433,9 @@ public static Exception RunTriggerFailure<TResult>(IStorageAccount account, Type
}

Assert.Equal(TaskStatus.RanToCompletion, failureTask.Status);
return failureTask.Result;
Exception exception = failureTask.Result;
Assert.IsType<FunctionInvocationException>(exception);
return exception.InnerException;
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,12 @@ private static void TestBindToConcurrentlyUpdatedTableEntity(Type programType, s

private static void AssertInvocationETagFailure(string expectedParameterName, Exception exception)
{
Assert.IsType<InvalidOperationException>(exception);
Assert.IsType<FunctionInvocationException>(exception);
Assert.IsType<InvalidOperationException>(exception.InnerException);
string expectedMessage = String.Format(CultureInfo.InvariantCulture,
"Error while handling parameter {0} after function returned:", expectedParameterName);
Assert.Equal(expectedMessage, exception.Message);
Exception innerException = exception.InnerException;
Assert.Equal(expectedMessage, exception.InnerException.Message);
Exception innerException = exception.InnerException.InnerException;
Assert.IsType<InvalidOperationException>(innerException);
// This exception is an implementation detail of the fake storage account. A real one would use a
// StorageException (this assert may need to change if the fake is updated to be more realistic).
Expand Down
14 changes: 7 additions & 7 deletions test/Microsoft.Azure.WebJobs.Host.UnitTests/JobHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ public void Call_WhenMethodThrows_PreservesStackTrace()
MethodInfo methodInfo = typeof(ThrowingProgram).GetMethod("Throw");

// Act & Assert
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(
FunctionInvocationException exception = Assert.Throws<FunctionInvocationException>(
() => host.Call(methodInfo));
Assert.Same(exception, expectedException);
Assert.NotNull(exception.StackTrace);
Assert.True(exception.StackTrace.StartsWith(expectedStackTrace));
Assert.Same(exception.InnerException, expectedException);
Assert.NotNull(exception.InnerException.StackTrace);
Assert.True(exception.InnerException.StackTrace.StartsWith(expectedStackTrace));
}
finally
{
Expand Down Expand Up @@ -429,11 +429,11 @@ public void QueueTrigger_WithNonTextualByteArrayMessageUsingQueueTriggerBindingD
CloudQueueMessage message = new CloudQueueMessage(contents);

// Act & Assert
Exception exception = Assert.Throws<InvalidOperationException>(
FunctionInvocationException exception = Assert.Throws<FunctionInvocationException>(
() => host.Call(methodInfo, new { message = message }));
// This exeption shape/message could be better, but it's meets a minimum acceptibility threshold.
Assert.Equal("Exception binding parameter 'queueTrigger'", exception.Message);
Exception innerException = exception.InnerException;
Assert.Equal("Exception binding parameter 'queueTrigger'", exception.InnerException.Message);
Exception innerException = exception.InnerException.InnerException;
Assert.IsType<InvalidOperationException>(innerException);
Assert.Equal("Binding data does not contain expected value 'queueTrigger'.", innerException.Message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public async Task TryLockAsync_CreatesBlobLease_WithAutoRenewal()
await _singletonManager.ReleaseLockAsync(lockHandle, cancellationToken);

// verify the traces
Assert.Equal(1, _trace.Traces.Count(p => p.ToString().Contains("Verbose WebJobs.Execution Waiting for Singleton lock (testid)")));
Assert.Equal(1, _trace.Traces.Count(p => p.ToString().Contains("Verbose WebJobs.Execution Singleton lock acquired (testid)")));
Assert.Equal(1, _trace.Traces.Count(p => p.ToString().Contains("Verbose Waiting for Singleton lock (testid)")));
Assert.Equal(1, _trace.Traces.Count(p => p.ToString().Contains("Verbose Singleton lock acquired (testid)")));
Assert.Equal(renewCount, _trace.Traces.Count(p => p.ToString().Contains("Renewing Singleton lock (testid)")));
Assert.Equal(1, _trace.Traces.Count(p => p.ToString().Contains("Verbose WebJobs.Execution Singleton lock released (testid)")));
Assert.Equal(1, _trace.Traces.Count(p => p.ToString().Contains("Verbose Singleton lock released (testid)")));

renewCount = 0;
await Task.Delay(1000);
Expand Down

0 comments on commit 1ab4ee5

Please sign in to comment.