On 02/01/2013 06:21 AM, Julian Schmidt wrote:
do you know how to reproduce this? A fix this important deserves a regression 
test.

I though I did that

Reproduced manually, or added a test? #688 [1] has no test changes. If I can 
get some time to work on this pull request I will see if I can reproduce in a 
test.

it is triggered by garbage-collection, which does not seem to be 100% 
deterministic

Indeed it is not. If the bug is caused reliably when garbage collection happens, then writing a test is not hard: just call System.gc(). That is not _guaranteed_ to collect everything, which is why it is sometimes necessary to use tricks [2] to force collection, especially if the test will fail unless something is collected. In this case it is more likely that an incomplete collection would just make the test not fail reliably enough with the fix not applied, which is tolerable if the developer is willing to run the test a few times with and without the proposed fix.

(If the bug is caused when GC does _not_ happen then it is trickier to write a test, though sometimes still possible, by explicitly holding a strong reference to a certain object from test code.)

What would be useful is a MockWeakReference<T> extends Reference<T>, with an injectable ReferenceFactory<T> used by Jenkins code (default impl creating WeakReference<T>), so that a test could deterministically “collect” specific references at specific times.


[1] https://github.com/jenkinsci/jenkins/pull/688/files
[2] 
http://hg.netbeans.org/main-silver/file/default/nbjunit/src/org/netbeans/junit/NbTestCase.java#l1379

--
You received this message because you are subscribed to the Google Groups "Jenkins 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to