Volodymyr Bezuglyy
Volodymyr Bezuglyy

Reputation: 16795

Silk Test Open Agent locks trace file

We have testing java application.
This application performs different types of testing. On one step it starts Silk Test.
This application writes a lot of traces using System.out.println.
We redirect this traces to file app.trace in our cmd file.
Something like:

java com.test.app > app.trace

When this testing application stops it is not possible to remove app.trace file because it is locked by Silk Test Open Agent.
I do not understand how this application can lock our trace file.
We do not start this application directly from our code.
We use Silk4J lib to start Silk Test.
As far as I know this library connects to Silk Test windows service which starts Silk Test Open Agent.
Does anyone can explain me - why and how Silk Test Open Agent locks our trace file?

Upvotes: 1

Views: 1268

Answers (2)

tehlexx
tehlexx

Reputation: 2859

The reason is that child processes inherit the open files of their parents, in this case the redirected output stream to the file. This makes sense, as is allows you to also capture the output of those child processes.

However, otherwise than David Genrich suggested in his answer, I would not forcefully kill the agent as it may then fail to release some resources and clean up properly. This might lead to follow-up problems.

I suggest separately starting the OpenAgent before you run your tests so it's not a child process of the test runner.

Upvotes: 0

David Genrich
David Genrich

Reputation: 11

The cause of this is because Open Agent does not close down when the test finishes. I just kill Open Agent when my suite is done.

public class ProcessKill {

public void killOpenAgent ()    {
    kill ("openAgent.exe");
}

public void kill (String processName)   {
    String command = "cmd /c taskkill";
    String parameter = " /F /IM " + processName;
    System.out.println("Killing process: " + processName);

    try {
        Runtime.getRuntime().exec(command + parameter);
    } catch (IOException e) {
        e.printStackTrace();
    }       
}
}

I am using TestNG to control my tests, so I just call this from the @AfterSuite method to always make sure that Open Agent is killed after each run. This also helps to release the licence.

Upvotes: 1

Related Questions