public async ValueTask DisposeAsync()
        {
            _logger.Write("[Dispose] Executing");
            await _connection.CloseAsync();

            _watcher.Dispose();
            _logger.Write("[Dispose] Executed");
            await _logger.DisposeAsync();

            await Writer.DisposeAsync();
        }
Пример #2
0
        public async Task HandleCallbackException(ConnectionState throwOnState, ConnectionState expectedState)
        {
            var settings = GetDefaultConnectionSettings();

            await using var connection = new ClickHouseConnection(settings);
            connection.StateChange    += OnStateChanged;

            var ex = await Assert.ThrowsAnyAsync <ClickHouseException>(async() =>
            {
                await connection.OpenAsync();
                await connection.CloseAsync();
            });

            Assert.Equal(expectedState, connection.State);
            Assert.Equal(ClickHouseErrorCodes.CallbackError, ex.ErrorCode);
            Assert.NotNull(ex.InnerException);
            Assert.Equal("You shall not pass!", ex.InnerException !.Message);

            void OnStateChanged(object sender, StateChangeEventArgs e)
            {
                Assert.Same(sender, connection);

                if (e.CurrentState == throwOnState)
                {
                    throw new Exception("You shall not pass!");
                }
            }
        }