Programatically detecting whether EventStore is ready

Hi

For integration test purposes, is there a recommend way of checking whether a newly started EventStore is ready for clients?

Thank you.

Hi,

How are you starting it? Via Process.Start?

James

Yes, with Process.Start.

I’m working with Fredrik and can expand a little on what we are trying to achieve and how it is done.
We are trying to figure out the best way of testing the eventstore and any code built on top of it,

Currently we are experimenting with starting a new in-memory eventstore for every unit test.

Our initialization code is:

private void SetUpEventStore()
{

``

tcpPort = SomeFreeTcpPort()
StartEventStoreServer() //Using Process.Start

``

        autoResetEvent = new AutoResetEvent(false);

        var connectionSettings = ConnectionSettings.Create()

                                                  .KeepRetrying()

                                                  .SetReconnectionDelayTo(TimeSpan.FromSeconds(1))

                                                  .LimitReconnectionsTo(5)

                                                  .OnConnected(DoAfterConnectionEstablished)

                                                  .SetHeartbeatInterval(TimeSpan.FromMilliseconds(200))

                                                  .SetHeartbeatTimeout(TimeSpan.FromSeconds(5));

       Connection = EventStoreConnection.Create(connectionSettings, new IPEndPoint(IPAddress.Loopback, tcpPort));

       Connection .Connect();

        if (autoResetEvent.WaitOne(10000))

``

{

``

EnableByCategoryProjection //A post request to the eventstore with ‘projection/%24by_category/command/enable’
Retry above code several times in case it fails
Throw Exeption if all the tries fails.

``

}

``

Throw exeption as the connection could not connect

``

}

private void DoAfterConnectionEstablished(IEventStoreConnection eventStoreConnection, IPEndPoint ipEndPoint)

{

``

autoResetEvent.Set();

``

}

``

Our problem seems to be that sometimes the unit test successfully enable the projection.

Other times the keep trying up to 5 times, but fails each time.

Is there a better way to know when the eventstore is ready to receive the enable projection command?

A better way to enabling the projection?

Is the eventstore ready for testing when the projection has been enabled? If not, how do you check whether the eventstore has enabled the projection.

I am curious is your goal to unit test a projection?

Our goal is to test a repository we have built on top of the eventstore, which takes care of inserts, reads and subscriptions to the eventstore.
The repository can be inherited and the category overwritten to facilitate the saving and retrieval of data of a new class built by events.

The projection is therefore central to our repository.

I, for now, use a pretty crude solution of just reading log output from the inmem store to know when it’s up and running…

Something along the lines of ( https://gist.github.com/jokokko/ac846a7ee2c83d3754da ) :

var mre = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(state =>
{
process.Start();
while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(line) && line.Contains(“SPARTA”))
{
mre.Set();
}
}
});

Hah, interesting method.

If you’re connecting, why not just stick signal in the callback for ConnectAsync()?