Skip to content

Commit

Permalink
Merge branch 'release-1.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Simons committed Feb 23, 2016
2 parents ef197b0 + 4afc98d commit fe32196
Show file tree
Hide file tree
Showing 51 changed files with 1,179 additions and 466 deletions.
7 changes: 5 additions & 2 deletions src/ServiceControl.AcceptanceTesting/ScenarioContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NServiceBus.AcceptanceTesting
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Activation;
Expand Down Expand Up @@ -66,13 +67,15 @@ public IMessage SyncProcessMessage(IMessage msg)

public bool HasNativePubSubSupport { get; set; }

public string Trace { get; set; }
public string Trace { get { return string.Join(Environment.NewLine, traceQueue.ToArray()); } }

public void AddTrace(string trace)
{
Trace += DateTime.Now.ToString("HH:mm:ss.ffffff") + " - " + trace + Environment.NewLine;
traceQueue.Enqueue(String.Format("{0:HH:mm:ss.ffffff} - {1}", DateTime.Now, trace));
}

ConcurrentQueue<string> traceQueue = new ConcurrentQueue<string>();

public void RecordEndpointLog(string endpointName,string level ,string message)
{
endpointLogs.Add(new EndpointLogItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public EndpointConfiguration()
TypesToExclude = new List<Type>();
TypesToInclude = new List<Type>();
GetBus = () => null;
StopBus = null;
}

public IDictionary<Type, Type> EndpointMappings { get; set; }
Expand All @@ -23,6 +24,8 @@ public EndpointConfiguration()

internal Func<IStartableBus> GetBus { get; set; }

internal Action StopBus { get; set; }

public string EndpointName
{
get
Expand All @@ -49,9 +52,10 @@ public string EndpointName
public Type AuditEndpoint { get; set; }
public bool SendOnly { get; set; }

public void SelfHost(Func<IStartableBus> getBus)
public void SelfHost(Func<IStartableBus> getBus, Action stopBus)
{
GetBus = getBus;
StopBus = stopBus;
}

string endpointName;
Expand Down
25 changes: 19 additions & 6 deletions src/ServiceControl.AcceptanceTesting/Support/EndpointRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ public Result Initialize(RunDescriptor run, EndpointBehavior endpointBehavior,
}

//we spin around each 5s since the callback mechanism seems to be shaky
await contextChanged.WaitAsync(TimeSpan.FromSeconds(5), stopToken);

if (stopToken.IsCancellationRequested)
try
{
await contextChanged.WaitAsync(TimeSpan.FromSeconds(5), stopToken);
}
catch (OperationCanceledException)
{
break;
}

foreach (var when in behavior.Whens)
{
if (stopToken.IsCancellationRequested)
{
return;
}

if (executedWhens.Contains(when.Id))
{
continue;
Expand All @@ -104,7 +110,7 @@ public Result Initialize(RunDescriptor run, EndpointBehavior endpointBehavior,
}
}
}
}, stopToken).Unwrap();
}).Unwrap();
}
return Result.Success();
}
Expand Down Expand Up @@ -171,7 +177,14 @@ public Result Stop()
}
else
{
bus.Dispose();
if (configuration.StopBus != null)
{
configuration.StopBus();
}
else
{
bus.Dispose();
}
}

Cleanup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public BusConfiguration GetConfiguration(RunDescriptor runDescriptor, EndpointCo

configurationBuilderCustomization(builder);

var startableBus = new Bootstrapper(configuration: builder).Bus;
var bootstrapper = new Bootstrapper(configuration: builder);

LogManager.Configuration = SetupLogging(endpointConfiguration);

endpointConfiguration.SelfHost(() => startableBus);
endpointConfiguration.SelfHost(() => bootstrapper.Bus, () => bootstrapper.Stop());


return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class When_a_periodic_custom_check_fails : AcceptanceTest
[Test]
public void Should_result_in_a_custom_check_failed_event()
{
var context = new MyContext();

var context = new MyContext
{
SignalrStarted = true
};
EventLogItem entry = null;

Scenario.Define(context)
Expand All @@ -37,12 +39,10 @@ public void Should_result_in_a_custom_check_failed_event()
[Test]
public void Should_raise_a_signalr_event()
{
var context = new MyContext
var context = Scenario.Define(() => new MyContext
{
SCPort = port
};

Scenario.Define(context)
})
.WithEndpoint<ManagementEndpoint>(c => c.AppConfig(PathToAppConfig))
.WithEndpoint<EndpointWithFailingCustomCheck>()
.WithEndpoint<EndpointThatUsesSignalR>()
Expand All @@ -51,12 +51,13 @@ public void Should_raise_a_signalr_event()

Assert.IsNotNull(context.SignalrData);
}

public class MyContext : ScenarioContext
{
public bool SignalrEventReceived { get; set; }
public string SignalrData { get; set; }
public int SCPort { get; set; }
public bool SignalrStarted { get; set; }
}

public class EndpointThatUsesSignalR : EndpointConfigurationBuilder
Expand All @@ -81,12 +82,14 @@ public void Start()
{
connection.JsonSerializer = Newtonsoft.Json.JsonSerializer.Create(SerializationSettingsFactoryForSignalR.CreateDefault());
connection.Received += ConnectionOnReceived;
connection.StateChanged += change => { context.SignalrStarted = change.NewState == ConnectionState.Connected; };

while (true)
{
try
{
connection.Start().Wait();

break;
}
catch (AggregateException ex)
Expand Down Expand Up @@ -125,31 +128,31 @@ public void Stop()

public class EndpointWithFailingCustomCheck : EndpointConfigurationBuilder
{

public EndpointWithFailingCustomCheck()
{
EndpointSetup<DefaultServerWithoutAudit>();
}

class FailingCustomCheck : PeriodicCheck
{
private readonly MyContext context;
bool executed;

public FailingCustomCheck() : base("MyCustomCheckId", "MyCategory", TimeSpan.FromSeconds(5))
public FailingCustomCheck(MyContext context) : base("MyCustomCheckId", "MyCategory", TimeSpan.FromSeconds(5))
{
this.context = context;
}

public override CheckResult PerformCheck()
{
if (executed)
if (executed && context.SignalrStarted)
{
return CheckResult.Failed("Some reason");
}

executed = true;

return CheckResult.Pass;

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void SubsequentBatchesShouldBeProcessed()
var context = new MyContext();

Scenario.Define(context)
.WithEndpoint<ManagementEndpoint>(ctx => ctx.AppConfig(PathToAppConfig))
.WithEndpoint<FailureEndpoint>(ctx => ctx
.WithEndpoint<ManagementEndpoint>(cfg => cfg.AppConfig(PathToAppConfig))
.WithEndpoint<FailureEndpoint>(cfg => cfg
.When(bus =>
{
while (true)
Expand All @@ -39,23 +39,13 @@ public void SubsequentBatchesShouldBeProcessed()
}

bus.SendLocal(new MessageThatWillFail());
}))
.Done(ctx =>
{
if (ctx.IssueRetry)
})
.When(ctx =>
{
object failure;
if (!TryGet("/api/errors/" + ctx.UniqueMessageId, out failure))
{
return false;
}

ctx.IssueRetry = false;
Post<object>(String.Format("/api/errors/{0}/retry", ctx.UniqueMessageId));
}

return ctx.Done;
})
return ctx.IssueRetry && TryGet("/api/errors/" + ctx.UniqueMessageId, out failure);
}, (bus, ctx) => Post<object>(string.Format("/api/errors/{0}/retry", ctx.UniqueMessageId))))
.Done(ctx => ctx.Done)
.Run(TimeSpan.FromMinutes(3));

Assert.IsTrue(context.Done);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using ServiceControl.Infrastructure;
using ServiceControl.MessageFailures;

[Serializable]
public class When_a_group_is_archived : AcceptanceTest
{
[Test]
Expand All @@ -25,25 +26,46 @@ public void All_messages_in_group_should_get_archived()
Scenario.Define(context)
.WithEndpoint<ManagementEndpoint>(c => c.AppConfig(PathToAppConfig))
.WithEndpoint<Receiver>(b => b.Given(bus =>
{
bus.SendLocal<MyMessage>(m => m.MessageNumber = 1);
bus.SendLocal<MyMessage>(m => m.MessageNumber = 2);
}))
.Done(c =>
{
if (c.FirstMessageId == null || c.SecondMessageId == null)
return false;

if (!c.ArchiveIssued)
{
List<FailedMessage.FailureGroup> beforeArchiveGroups;
bus.SendLocal<MyMessage>(m => m.MessageNumber = 1);
bus.SendLocal<MyMessage>(m => m.MessageNumber = 2);
})
.When(ctx =>
{
if (ctx.ArchiveIssued || ctx.FirstMessageId == null || ctx.SecondMessageId == null)
{
return false;
}

List<FailedMessage.FailureGroup> beforeArchiveGroups;
if (!TryGetMany("/api/recoverability/groups/", out beforeArchiveGroups))
return false;

Post<object>(String.Format("/api/recoverability/groups/{0}/errors/archive", beforeArchiveGroups[0].Id));
c.ArchiveIssued = true;
}
foreach (var group in beforeArchiveGroups)
{
List<FailedMessage> failedMessages;
if (TryGetMany(string.Format("/api/recoverability/groups/{0}/errors", group.Id), out failedMessages))
{
if (failedMessages.Count == 2)
{
ctx.GroupId = group.Id;
return true;
}
}
}

return false;

}, (bus, ctx) =>
{
Post<object>(string.Format("/api/recoverability/groups/{0}/errors/archive", ctx.GroupId));
ctx.ArchiveIssued = true;
})
)
.Done(c =>
{
if (c.FirstMessageId == null || c.SecondMessageId == null)
return false;

if (!TryGet("/api/errors/" + c.FirstMessageId, out firstFailure, e => e.Status == FailedMessageStatus.Archived))
return false;
Expand Down Expand Up @@ -170,12 +192,14 @@ public class MyMessage : ICommand
public int MessageNumber { get; set; }
}

[Serializable]
public class MyContext : ScenarioContext
{
public string FirstMessageId { get; set; }
public string SecondMessageId { get; set; }
public bool ArchiveIssued { get; set; }
public bool RetryIssued { get; set; }
public string GroupId { get; set; }
}
}
}
Loading

0 comments on commit fe32196

Please sign in to comment.