Exemplo n.º 1
0
        public void TestLoginTimeout()
        {
            using (IDbConnection conn = new MockSnowflakeDbConnection())
            {
                int    timeoutSec       = 5;
                string loginTimeOut5sec = String.Format(ConnectionString + "connection_timeout={0}",
                                                        timeoutSec);

                conn.ConnectionString = loginTimeOut5sec;

                Assert.AreEqual(conn.State, ConnectionState.Closed);
                try
                {
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    conn.Open();
                    stopwatch.Stop();
                    Assert.Fail();
                    //Should timeout before the default timeout (15min) * 60 * 1000
                    Assert.Less(stopwatch.ElapsedMilliseconds, 15 * 60 * 1000);
                    // Should timeout after the defined connection timeout
                    Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, timeoutSec * 1000);
                }
                catch (AggregateException e)
                {
                    Assert.AreEqual(SFError.REQUEST_TIMEOUT.GetAttribute <SFErrorAttr>().errorCode,
                                    ((SnowflakeDbException)e.InnerException).ErrorCode);
                }
                Assert.AreEqual(5, conn.ConnectionTimeout);
            }
        }
Exemplo n.º 2
0
        public void TestAsyncDefaultLoginTimeout()
        {
            using (var conn = new MockSnowflakeDbConnection())
            {
                conn.ConnectionString = ConnectionString;

                Assert.AreEqual(conn.State, ConnectionState.Closed);

                CancellationTokenSource connectionCancelToken = new CancellationTokenSource();
                Stopwatch stopwatch = Stopwatch.StartNew();
                try
                {
                    Task connectTask = conn.OpenAsync(connectionCancelToken.Token);
                    connectTask.Wait();
                }
                catch (AggregateException e)
                {
                    Assert.AreEqual(SFError.INTERNAL_ERROR.GetAttribute <SFErrorAttr>().errorCode,
                                    ((SnowflakeDbException)e.InnerException).ErrorCode);
                }
                stopwatch.Stop();

                // Should timeout after the default timeout (120 sec)
                Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 120 * 1000);
                // But never more than 16 sec (max backoff) after the default timeout
                Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, (120 + 16) * 1000);

                Assert.AreEqual(ConnectionState.Closed, conn.State);
                Assert.AreEqual(120, conn.ConnectionTimeout);
            }
        }
Exemplo n.º 3
0
        public void TestDefaultLoginTimeout()
        {
            using (IDbConnection conn = new MockSnowflakeDbConnection())
            {
                conn.ConnectionString = ConnectionString;

                // Default timeout is 15 min
                Assert.AreEqual(15 * 60, conn.ConnectionTimeout);

                Assert.AreEqual(conn.State, ConnectionState.Closed);
                try
                {
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    conn.Open();
                    stopwatch.Stop();
                    //Should timeout after the default timeout (15min)
                    Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 15 * 60 * 1000);
                    Assert.Fail();
                }
                catch (AggregateException e)
                {
                    Assert.AreEqual(SFError.REQUEST_TIMEOUT.GetAttribute <SFErrorAttr>().errorCode,
                                    ((SnowflakeDbException)e.InnerException).ErrorCode);
                }
            }
        }
Exemplo n.º 4
0
        public void TestDefaultLoginTimeout()
        {
            using (IDbConnection conn = new MockSnowflakeDbConnection())
            {
                conn.ConnectionString = ConnectionString;

                // Default timeout is 120 sec
                Assert.AreEqual(120, conn.ConnectionTimeout);

                Assert.AreEqual(conn.State, ConnectionState.Closed);
                Stopwatch stopwatch = Stopwatch.StartNew();
                try
                {
                    conn.Open();
                    Assert.Fail();
                }
                catch (AggregateException e)
                {
                    Assert.AreEqual(SFError.REQUEST_TIMEOUT.GetAttribute <SFErrorAttr>().errorCode,
                                    ((SnowflakeDbException)e.InnerException).ErrorCode);
                }
                stopwatch.Stop();
                // Should timeout after the default timeout (120 sec)
                Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 120 * 1000);
                // But never more than 16 sec (max backoff) after the default timeout
                Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, (120 + 16) * 1000);
            }
        }
Exemplo n.º 5
0
        public void TestCancelLoginBeforeTimeout()
        {
            using (var conn = new MockSnowflakeDbConnection())
            {
                // No timeout
                int    timeoutSec           = 0;
                string infiniteLoginTimeOut = String.Format(ConnectionString + ";connection_timeout={0}",
                                                            timeoutSec);

                conn.ConnectionString = infiniteLoginTimeOut;

                Assert.AreEqual(conn.State, ConnectionState.Closed);
                // At this point the connection string has not been parsed, it will return the
                // default value
                //Assert.AreEqual(15, conn.ConnectionTimeout);

                CancellationTokenSource connectionCancelToken = new CancellationTokenSource();
                logger.Debug("TestNoLoginTimeout token " + connectionCancelToken.Token.GetHashCode());

                Task connectTask = conn.OpenAsync(connectionCancelToken.Token);

                // Sleep for 16min (more than the default connection timeout and the httpclient
                // timeout to make sure there are no false positive )
                Thread.Sleep(16 * 60 * 1000);

                Assert.AreEqual(ConnectionState.Connecting, conn.State);

                // Cancel the connection because it will never succeed since there is no
                // connection_timeout defined
                logger.Debug("connectionCancelToken.Cancel ");
                connectionCancelToken.Cancel();

                try
                {
                    connectTask.Wait();
                }
                catch (AggregateException e)
                {
                    Assert.AreEqual(
                        "System.Threading.Tasks.TaskCanceledException",
                        e.InnerException.GetType().ToString());
                }

                Assert.AreEqual(ConnectionState.Closed, conn.State);
                Assert.AreEqual(0, conn.ConnectionTimeout);
            }
        }