Skip to content

Commit

Permalink
Fix test element name changing inside loop causing a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
almansour authored and almansour committed Dec 13, 2021
1 parent d06a552 commit 1d526ac
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SampleResult sample(Entry e) {
for (TestElement ctl : controllers) {
reqText.append(ctl.getName()).append("\n");
JMeterThread jmThread = new JMeterThreadParallel(getTestTree(ctl), this, notifier, getGenerateParent());
String name = JMeterContextService.getContext().getThread() + " - " + this.getName() + " - " + ctl.getName();
String name = JMeterContextService.getContext().getThread().toString();
jmThread.setThreadName(name);
jmThread.setThreadGroup(threadGroup);
jmThread.setEngine(JMeterContextService.getContext().getEngine());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ public void underLoop() throws Exception {
assertEquals(5, EmulSampler.count.get());
}

@Test
public void underLoopWithIterationNumber() throws Exception {
EmulSampler payload = new NameChangingEmulSampler();
payload.setName("payload");

ParallelSampler sam = new ParallelSampler();
sam.threadStarted();
sam.setName("Parallel Sampler");
sam.addTestElement(payload);

LoopController ctl = getLoopController(5);
ctl.addTestElement(sam);

JMeterThread thr = new JMeterThread(new HashTree(ctl), sam, sam.notifier);
thr.setThreadName("root");
thr.setThreadGroup(new DummyThreadGroup());
JMeterContextService.getContext().setThread(thr);

addToContext(sam, thr);
addToContext(payload, thr);

sam.setRunningVersion(true);
ctl.setRunningVersion(true);
payload.setRunningVersion(true);
thr.run();
assertEquals(5, EmulSampler.count.get());
}

private LoopController getLoopController(int loops) {
LoopController ctl = new LoopControllerTracked();
ctl.setName("Top Loop");
Expand All @@ -149,7 +177,7 @@ public void addToContext(TestElement te, JMeterThread parentThread) throws NoSuc

public static class EmulSampler extends DummySampler {
private volatile transient static int instances = 0;
private volatile transient static AtomicInteger count = new AtomicInteger();
protected volatile transient static AtomicInteger count = new AtomicInteger();

public EmulSampler() {
instances++;
Expand All @@ -164,6 +192,17 @@ public SampleResult sample(Entry e) {
}
}

public static class NameChangingEmulSampler extends EmulSampler {

public NameChangingEmulSampler() {
super();
}

@Override
public String getName() {
return super.getName() + count.get();
}
}

@Test
public void testThreadSafeCookieManager() throws Exception {
Expand Down

0 comments on commit 1d526ac

Please sign in to comment.