I’m trying to use an embedded event store to run my tests, stopping it and starting a new one for every test. I’m using ProjectionsManager to create and enable a projection on every embedded event store I start. Here is the code in my [SetUp]:
var tcp = new IPEndPoint(IPAddress.Loopback, 9721);
var http = new IPEndPoint(IPAddress.Loopback, 9722);
_vnode = EmbeddedVNodeBuilder
.AsSingleNode()
.RunInMemory()
.WithInternalTcpOn(tcp)
.WithInternalHttpOn(http)
.WithExternalTcpOn(tcp)
.WithExternalHttpOn(http)
.AddExternalHttpPrefix(“http://+:9722/”)
.RunProjections(ProjectionsMode.All)
.StartStandardProjections()
.Build();
_vnode.StartAndWaitUntilReady().Wait();
_connection = EmbeddedEventStoreConnection.Create(_vnode,
ConnectionSettings.Create()
.EnableVerboseLogging()
.UseConsoleLogger()
.SetDefaultUserCredentials(new UserCredentials(“admin”, “changeit”))
.Build());
var projectionsManager = new ProjectionsManager(_logger, http, TimeSpan.FromSeconds(60));
projectionsManager.CreateContinuousAsync("$by_event_name", @"
fromAll().whenAny(function(s,e) {
if (e.metadata === null) return;
var eventName = e.metadata.eventName;
if (!eventName) return;
var lastDot = e.streamId.lastIndexOf(’.’);
if (lastDot == -1) return;
var namespace = e.streamId.slice(0, lastDot);
linkTo(’$en-’ + namespace + ‘.’ + eventName, e);
})", new UserCredentials(“admin”, “changeit”)).Wait();
projectionsManager.EnableAsync("$by_event_name", new UserCredentials(“admin”, “changeit”)).Wait();
``
and my [TearDown] is:
_vnode.Stop();
_connection.Close();
``
I’ve also tried using _vnode.Stop(TimeSpan.FromSeconds(60), true, true) in place of _vnode.Stop() to make sure it shuts down good and proper.
The first test I run always seems to work fine, but subsequent tests in the same session intermittently time out with a 408 when the ProjectionsManager tries to hit the event store over HTTP. Accessing it with the EmbeddedEventStoreConnection always seems to work if I try it; it’s only the ProjectionsManager that ever fails. As an aside, when I stopped trying to create my own projection and tried to just use the standard projections, I think I also encountered a situation where they weren’t running after a few test cases, but I haven’t managed to reproduce that consistently. I’m currently running version 3.5.2 of the NuGet packages, but I encountered the same behavior after upgrading to 3.6.2. The error I get is:
SetUp : System.AggregateException : One or more errors occurred.
----> EventStore.ClientAPI.Exceptions.ProjectionCommandFailedException : Server returned 408 (Server was unable to handle request in time) for POST on http://127.0.0.1:9722/projections/continuous?name=$by_event_name&type=JS&emit=1
``