Пример #1
0
        public void TestCommandTimeout()
        {
            Random rnd = RandomInstance;
            DataStressConnection conn = null;

            try
            {
                // Use a transaction 50% of the time
                if (rnd.NextBool())
                {
                }

                // Create a select command
                conn = Factory.CreateConnection(rnd);
                if (!OpenConnection(conn))
                {
                    return;
                }
                DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);
                DbCommand com = Factory.GetSelectCommand(rnd, table, conn);

                // Setup timeout. We want to see various possibilities of timeout happening before, after, or at the same time as when the result comes in.
                int delay   = rnd.Next(0, 10); // delay is from 0 to 9 seconds inclusive
                int timeout = rnd.Next(1, 10); // timeout is from 1 to 9 seconds inclusive
                com.CommandText   += string.Format("; WAITFOR DELAY '00:00:0{0}'", delay);
                com.CommandTimeout = timeout;

                // Execute command and catch timeout exception
                try
                {
                    CommandExecute(rnd, com, true);
                }
                catch (DbException e)
                {
                    if (e is SqlException && ((SqlException)e).Number == 3989)
                    {
                        throw DataStressErrors.ProductError("Timing issue between OnTimeout and ReadAsyncCallback results in SqlClient's packet parsing going out of sync", e);
                    }
                    else if (!e.Message.ToLower().Contains("timeout"))
                    {
                        throw;
                    }
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Dispose();
                }
            }
        }