Exemplo n.º 1
0
        private void RunTest(SqlConnection con, RandomizerPool.Scope <SqlRandomizer> testScope, SqlRandomTypeInfoCollection types, Stopwatch watch)
        {
            Exception pendingException = null;
            string    tempTableName    = null;

            try
            {
                // select number of columns to use and null bitmap to test
                int columnsCount, rowsCount;
                testScope.Current.NextTableDimentions(MaxRows, MaxColumns, MaxTotal, out rowsCount, out columnsCount);
                SqlRandomTable table = SqlRandomTable.Create(testScope.Current, types, columnsCount, rowsCount, createPrimaryKeyColumn: true);

                long total = (long)rowsCount * columnsCount;
                Interlocked.Add(ref _totalValues, total);
                Interlocked.Increment(ref _totalTables);

                tempTableName = SqlRandomizer.GenerateUniqueTempTableNameForSqlServer();
                table.GenerateTableOnServer(con, tempTableName);

                long prevTicks = watch.ElapsedTicks;
                watch.Start();

                if (_randPool.ReproMode)
                {
                    // perform one iteration only
                    using (var iterationScope = testScope.NewScope <SqlRandomizer>())
                    {
                        RunTestIteration(con, iterationScope.Current, table, tempTableName);
                        Interlocked.Increment(ref _totalIterations);
                    }
                }
                else
                {
                    // continue with normal loop
                    for (int i = 0; i < IterationsPerTableDefault && watch.Elapsed < TimeLimitDefault; i++)
                    {
                        using (var iterationScope = testScope.NewScope <SqlRandomizer>())
                        {
                            RunTestIteration(con, iterationScope.Current, table, tempTableName);
                            Interlocked.Increment(ref _totalIterations);
                        }
                    }
                }

                watch.Stop();
                Interlocked.Add(ref _totalTicks, watch.ElapsedTicks - prevTicks);
            }
            catch (Exception e)
            {
                pendingException = e;
                throw;
            }
            finally
            {
                // keep the temp table for troubleshooting if debugger is attached
                // the thread is going down anyway and connection will be closed
                if (pendingException == null && tempTableName != null)
                {
                    // destroy the temp table to free resources on the server
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "DROP TABLE " + tempTableName;
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch
                    {
                    }
                }
            }
        }