Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for #544 and #545 #549

Merged
merged 9 commits into from
Dec 12, 2012
Merged

fixes for #544 and #545 #549

merged 9 commits into from
Dec 12, 2012

Conversation

Tibor17
Copy link
Contributor

@Tibor17 Tibor17 commented Nov 15, 2012

Simple fixes for #544 and #545.

Changes:

  • FailOnTimeout is now daemon thred.
  • StatementThread in FailOnTimeout uses volatile variables.
  • StatementThread catching two more exceptions when a thread is interrupted: InterruptedIOException and ClosedByInterruptException.
  • added NIO tests to TimeoutRuleTest.

@@ -29,6 +31,7 @@ public void evaluate() throws Throwable {

private StatementThread evaluateStatement() throws InterruptedException {
StatementThread thread = new StatementThread(fOriginalStatement);
thread.setDaemon(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about why this is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsaff
Sure, i can put a comment to the code.

For us here this would explain the problem more simply than FailOnTimeout.
The application does not exit unless setDaemon(true) is uncommented.

Thread t = new Thread() {
public void run() {
while (true) {
try {
System.out.println("run");
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(e.getLocalizedMessage());
}
}
}
};
/// t.setDaemon(true);
t.start();
t.join(1100);
t.interrupt();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking something like "Let the process complete even if this thread is not finished."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put the comment on its own line? (Style preference.) Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, can you put the comment on its own line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, can you put the comment on its own line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i will.
I missed that, sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I've been confusing. What I mean is that I find inline comments like this (especially without spaces) hard to read. So I'm recommending:

//Let the process/application complete after timeout expired.
thread.setDaemon(true);

@Tibor17
Copy link
Contributor Author

Tibor17 commented Nov 16, 2012

@dsaff

changes:

  • one tmp file per test;
  • reasons for volatile and daemon thread

* When declaring 'volatile' variables, the CPU is forced
* to reconcile the values stored in registers and thread's stack
* by cache coherence at every write-read operation on these variables
* ; Otherwise the CPU and VM may reconcile the memories as it wants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd to put semicolon at the beginning of a line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fixt it.
It will stay at end of previous line.

@Tibor17
Copy link
Contributor Author

Tibor17 commented Dec 6, 2012

@dsaff
Do you have time for this ?
Thx.

@Tibor17
Copy link
Contributor Author

Tibor17 commented Dec 10, 2012

@dsaff

This looks very simple pull. Nothing special.

Setting interrupted flag after the timeout has elapsed, which results in three exceptions in a thread due to that thread aborted.

Some final and volatile modifier as well as nice thread safety -to make sure we made all for 100% visibility.

* Besides visibility, the volatile variables have also other guarantees:
* atomicity and ordering.
* */
private volatile boolean fFinished;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a lesson on what volatile means. That's easy to Google. We need to indicate why these fields need to be volatile, and the others don't.

@dsaff
Copy link
Member

dsaff commented Dec 10, 2012

@Tibor17, I've made some comments in the code. Can you take a look?

@Tibor17
Copy link
Contributor Author

Tibor17 commented Dec 10, 2012

@dsaff

I answered all pending questions briefly.

  • updated with a brief comment in code for volatile as required
  • using TemporaryFolder as required by you
  • only one tmp file in a test as required by you
  • comment for deamon thread -let process finish after timeout expired

Random rnd = new Random();
byte[] data = new byte[1024];
File tmp = tmpFile.newFile();
tmp.deleteOnExit();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for deleteOnExit now.

@Tibor17
Copy link
Contributor Author

Tibor17 commented Dec 11, 2012

@dsaff

changes:

  • no need for #deleteOnExit
  • no inline comment
  • added space to a comment

dsaff pushed a commit that referenced this pull request Dec 12, 2012
@dsaff dsaff merged commit 345ba45 into junit-team:master Dec 12, 2012
@dsaff
Copy link
Member

dsaff commented Dec 12, 2012

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants