public static void TestMain() { _operationCanceledErrorMessage = SystemDataResourceManager.Instance.SQL_OperationCancelled; _severeErrorMessage = SystemDataResourceManager.Instance.SQL_SevereError; // pure random _randPool = new RandomizerPool(); SqlConnectionStringBuilder regularConnectionString = new SqlConnectionStringBuilder(); regularConnectionString.ConnectionString = DataTestClass.SQL2008_Master; regularConnectionString.MultipleActiveResultSets = false; List<string> connStrings = new List<string>(); connStrings.Add(regularConnectionString.ToString()); connStrings.Add(regularConnectionString.ToString()); regularConnectionString.MultipleActiveResultSets = true; connStrings.Add(regularConnectionString.ToString()); _connectionStrings = connStrings.ToArray(); _katmaiTypes = SqlRandomTypeInfoCollection.CreateSql2008Collection(); _endEvent = new ManualResetEvent(false); if (_randPool.ReproMode) { _runningThreads = 1; TestThread(); } else { for (int tcount = 0; tcount < ThreadCountDefault; tcount++) { Thread t = new Thread(TestThread); t.Start(); } } }
private static 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 { } } } }