public void TestConcurrentSynchronousOperations(IIpcProvider provider) { var testName = nameof(TestConcurrentSynchronousOperations); WithIpcServer( provider, EchoingExecutor, ServerConfigWithLogger(testName), (moniker, server) => { using (IClient client = provider.GetClient(provider.RenderConnectionString(moniker), ClientConfigWithLogger(testName))) { var threads = Enumerable .Range(1, 10) .Select(i => new Thread(() => { var message = "hi" + i; var op = new IpcOperation(message, waitForServerAck: true); var result = SendWithTimeout(client, op); Assert.True(result.Succeeded, "error: " + result.Payload); Assert.Equal(op.Payload, result.Payload); })) .ToArray(); Start(threads); Join(threads); client.RequestStop(); client.Completion.GetAwaiter().GetResult(); } }); }
public void TestWithExecutionError(IIpcProvider provider) { var testName = nameof(TestWithExecutionError); WithIpcServer( provider, CrashingExecutor, ServerConfigWithLogger(testName), (moniker, server) => { using (var client = provider.GetClient(provider.RenderConnectionString(moniker), ClientConfigWithLogger(testName))) { var syncOp = new IpcOperation("sync", waitForServerAck: true); var asyncOp = new IpcOperation("async", waitForServerAck: false); var syncResult = SendWithTimeout(client, syncOp); var asyncResult = SendWithTimeout(client, asyncOp); Assert.True(asyncResult.Succeeded, "Asynchronous operation is expected to succeed if executor crashes"); Assert.False(syncResult.Succeeded, "Synchronous operation is expected to fail if executor crashes"); Assert.Equal(IpcResultStatus.ExecutionError, syncResult.ExitCode); Assert.True(syncResult.Payload.Contains("System.Exception")); // because CrashingExecutor throws System.Exception Assert.True(syncResult.Payload.Contains(syncOp.Payload)); // because CrashingExecutor throws System.Exception whose message is equal to syncOp.Payload client.RequestStop(); client.Completion.GetAwaiter().GetResult(); } }); }
public void TestCreateDisposeClient(IIpcProvider provider) { var m1 = provider.CreateNewConnectionString(); using (provider.GetClient(m1, new ClientConfig())) { } }
/// <summary> /// If no client has been created for a given moniker, creates and returns a new client; /// otherwise, returns the client previously created for the same moniker. /// </summary> /// <inheritdoc /> public IClient GetClient(string connectionString, IClientConfig config) { lock (m_connectionString2Client) { return(m_connectionString2Client.GetOrAdd( key: connectionString, valueFactory: (s) => m_provider.GetClient(s, OverrideLogger(config)))); } }
public void TestClientMultipleDispose(IIpcProvider provider) { var testName = nameof(TestClientMultipleDispose); WithIpcServer( provider, EchoingExecutor, ServerConfigWithLogger(testName), (moniker, server) => { using (var client = provider.GetClient(provider.RenderConnectionString(moniker), ClientConfigWithLogger(testName))) { client.Dispose(); } }); }
public async Task TestWithConnectionErrorAsync(IIpcProvider provider) { var testName = nameof(TestWithConnectionErrorAsync); var connectionString = provider.CreateNewConnectionString(); var config = new ClientConfig() { Logger = VerboseLogger(testName), MaxConnectRetries = 2, ConnectRetryDelay = TimeSpan.FromMilliseconds(1) }; using var client = provider.GetClient(connectionString, config); var syncOpResult = await client.Send(new IpcOperation("sync hi", waitForServerAck : true)); var asyncOpResult = await client.Send(new IpcOperation("async hi", waitForServerAck : false)); // operations should fail because no server was started XAssert.AreEqual(IpcResultStatus.ConnectionError, syncOpResult.ExitCode); XAssert.AreEqual(IpcResultStatus.ConnectionError, asyncOpResult.ExitCode); XAssert.IsFalse(syncOpResult.Succeeded); XAssert.IsFalse(asyncOpResult.Succeeded); }
public void TestSimpleSyncOperation(IIpcProvider provider) { var testName = nameof(TestSimpleSyncOperation); WithIpcServer( provider, EchoingExecutor, ServerConfigWithLogger(testName), (moniker, server) => { using (var client = provider.GetClient(provider.RenderConnectionString(moniker), ClientConfigWithLogger(testName))) { var payload = "sync"; var syncOp = new IpcOperation(payload, waitForServerAck: true); var syncResult = SendWithTimeout(client, syncOp); Assert.True(syncResult.Succeeded, syncResult.Payload); Assert.Equal(syncResult.Payload, payload); client.RequestStop(); client.Completion.GetAwaiter().GetResult(); } }); }
internal static IClient CreateClient(ConfiguredCommand conf) { var daemonConfig = CreateDaemonConfig(conf); return(IpcProvider.GetClient(daemonConfig.Moniker, daemonConfig)); }
private IEnumerable <Thread> GetClientThreads(IIpcProvider ipcProvider, IEnumerable <string> ipcMonikers, int numServices, int numRequests, string cmdLine) { return(ipcMonikers .SelectMany(moniker => Enumerable .Range(1, numRequests) .Select(i => CreateThreadForCommand(cmdLine.Replace("<moniker>", moniker), ipcProvider.GetClient(moniker, new ClientConfig()))) .ToList()) .ToList()); }
private static Client CreateDummyBxlApiClient(IIpcProvider ipcProvider) { return(new Client(new MockClient(ipcProvider.GetClient(ipcProvider.CreateNewConnectionString(), new ClientConfig())))); }
private static Client CreateDummyBxlApiClient(IIpcProvider ipcProvider, IIpcMoniker moniker) { return(new Client(new MockClient(ipcProvider.GetClient(ipcProvider.RenderConnectionString(moniker), new ClientConfig())))); }