Ask a questionAsk a question
 

QuestionClassCleanup times out when executing a batch file

  • Sunday, November 01, 2009 11:00 PMJonathan_Bride Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    I am attempting to restore an Oracle database back to it's previous state by using flashback recovery using the ClassCleanup attribute

    I have written a batch file + sql commands to properly restore the database. This has been tested in my command prompt numerous times without issues

    I would normally put the restore as a cleanup script inside the test run, however I need to include a time to flashback the database to (set on the ClassInitialize)

                try
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo(@"SomeProjectDirectory\flashback.bat");                
                    startInfo.CreateNoWindow = false;                
                    startInfo.WindowStyle = ProcessWindowStyle.Normal;
                    startInfo.ErrorDialog = true;                
                    startInfo.Arguments = Arguments;
                    startInfo.UseShellExecute = true;                                                
                    
                    Process batchExecute = new Process();
                    batchExecute.StartInfo = startInfo;
                    batchExecute.Start();
                    batchExecute.WaitForExit();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                }
    

    The batch files is executed but the problem seems to be that the CleanUp method times out before it has finished executing.

    So far, I have tried:
    - Put breakpoints on points after the WaitForExit(), and none of them are hit.
    - Added a Timeout attribute to the ClassCleanup method with a large number but doesn't seem to help.
    - Moved the batch file into the TestCleanup and it worked without a problem

    Searching on the web came up with a similar problem but no solution

    Is there a reason why this occurs?

All Replies

  • Wednesday, November 04, 2009 6:50 AMEdwer FangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,

    Are there any warning or error messages? As I know, you may create a new bat file which will execute flashback.bat with proper arguments, then choose setup and cleanup script tab in the .testrunconfig file, select the new created file as cleanup script.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
  • Wednesday, November 04, 2009 10:41 PMJonathan_Bride Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    There are no warning or error messages. The test comes back successful

    The thought has occurred to me that I could create a new batch file during the ClassInitialize that could be run in the cleanup script. It isn't appropriate to me to build a workaround for something that should work but doesn't without any explanation why. If someone came back to me and stated it was a bug with Visual Studio, I could accept that and use whatever work around I needed to.

    Edit> It has also occurred to me that the cleanup script will only be run at the end of all my tests. The intention was to have the cleanup perform at the end of each class. Could work around this, however resolving the initial issue would be significantly better.