mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-15 21:12:15 +00:00
[FIXED JENKINS-10346] thread-safety problem when computing fingerprints
This commit is contained in:
1 parent
fa505a8c39
commit
3c09a0c43a
3 files changed
+58
-8
No files matched your search
@@ -32,6 +32,8 @@ import java.util.Locale;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
||||
import org.jvnet.hudson.test.Bug;
|
||||
|
||||
import hudson.util.StreamTaskListener;
|
||||
|
||||
/**
|
||||
@@ -177,4 +179,55 @@ public class UtilTest extends TestCase {
|
||||
assertEquals(""'", Util.escape("'\""));
|
||||
assertEquals(" ", Util.escape(" "));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute 'known-correct' digests and see if I still get them when computed concurrently
|
||||
* to another digest.
|
||||
*/
|
||||
@Bug(10346)
|
||||
public void testDigestThreadSafety() throws InterruptedException {
|
||||
String a = "abcdefgh";
|
||||
String b = "123456789";
|
||||
|
||||
String digestA = Util.getDigestOf(a);
|
||||
String digestB = Util.getDigestOf(b);
|
||||
|
||||
DigesterThread t1 = new DigesterThread(a, digestA);
|
||||
DigesterThread t2 = new DigesterThread(b, digestB);
|
||||
|
||||
t1.start();
|
||||
t2.start();
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
||||
if (t1.error != null) {
|
||||
fail(t1.error);
|
||||
}
|
||||
if (t2.error != null) {
|
||||
fail(t2.error);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DigesterThread extends Thread {
|
||||
private String string;
|
||||
private String expectedDigest;
|
||||
|
||||
private String error;
|
||||
|
||||
public DigesterThread(String string, String expectedDigest) {
|
||||
this.string = string;
|
||||
this.expectedDigest = expectedDigest;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (int i=0; i < 1000; i++) {
|
||||
String digest = Util.getDigestOf(this.string);
|
||||
if (!this.expectedDigest.equals(digest)) {
|
||||
this.error = "Expected " + this.expectedDigest + ", but got " + digest;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user