Exemple #1
0
        /// <summary>
        /// Utility method to test Async scenario using await keyword
        /// </summary>
        /// <returns></returns>
        protected virtual async Task TestCommandAndReaderAsyncInternal()
        {
            Random rnd = RandomInstance;

            using (DataStressConnection conn = Factory.CreateConnection(rnd))
            {
                if (!OpenConnection(conn))
                {
                    return;
                }
                DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);
                DbCommand com;

                com = Factory.GetInsertCommand(rnd, table, conn);
                await CommandExecuteAsync(rnd, com, false);

                com = Factory.GetDeleteCommand(rnd, table, conn);
                await CommandExecuteAsync(rnd, com, false);

                com = Factory.GetSelectCommand(rnd, table, conn);
                await com.ExecuteScalarAsync();

                com = Factory.GetSelectCommand(rnd, table, conn);
                await CommandExecuteAsync(rnd, com, true);
            }
        }
Exemple #2
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();
                }
            }
        }
Exemple #3
0
        public void TestCommandDelete()
        {
            Random rnd = RandomInstance;

            using (DataStressConnection conn = Factory.CreateConnection(rnd))
            {
                if (!OpenConnection(conn))
                {
                    return;
                }
                DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);
                DbCommand com = Factory.GetDeleteCommand(rnd, table, conn);
                CommandExecute(rnd, com, false);
            }
        }
Exemple #4
0
        /// <summary>
        /// Utility function used by MARS tests
        /// </summary>
        private void TestCommandMARS(Random rnd, bool query)
        {
            if (Source.Type != DataSourceType.SqlServer)
            {
                return; // skip for non-SQL Server databases
            }
            using (DataStressConnection conn = Factory.CreateConnection(rnd, DataStressFactory.ConnectionStringOptions.EnableMars))
            {
                if (!OpenConnection(conn))
                {
                    return;
                }
                DbCommand[] commands = new DbCommand[rnd.Next(5, 10)];
                List <Task> tasks    = new List <Task>();
                // Create commands
                for (int i = 0; i < commands.Length; i++)
                {
                    DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);
                    commands[i] = Factory.GetCommand(rnd, table, conn, query);
                }

                try
                {
                    // Execute commands
                    for (int i = 0; i < commands.Length; i++)
                    {
                        if (rnd.NextBool(0.7))
                        {
                            tasks.Add(CommandExecuteAsync(rnd, commands[i], query));
                        }
                        else
                        {
                            CommandExecute(rnd, commands[i], query);
                        }
                    }
                }
                finally
                {
                    // All commands must be complete before closing the connection
                    AsyncUtils.WaitAll(tasks.ToArray());
                }
            }
        }