Skip to content

Add CacheTest for dataprovider issue 3236 #3237

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import test.dataprovider.issue3045.DataProviderWithoutListenerTestClassSample;
import test.dataprovider.issue3081.NoOpMethodInterceptor;
import test.dataprovider.issue3081.TestClassWithPrioritiesSample;
import test.dataprovider.issue3236.CacheTest;

public class DataProviderTest extends SimpleBaseTest {

Expand Down Expand Up @@ -716,6 +717,16 @@ public void testIfDataProviderListenerInvokedOnlyOncePerDataProviderWhenListener
runTest(DataProviderWithoutListenerTestClassSample.class, true);
}

@Test(description = "GITHUB-3236")
public void testDataProviderReturnsFreshDataWhenTestRetried() {
TestNG testng = create(CacheTest.class);
TestListenerAdapter tla = new TestListenerAdapter();
testng.addListener(tla);
testng.run();
assertThat(tla.getFailedTests()).size().isEqualTo(0);
assertThat(tla.getSkippedTests()).size().isEqualTo(1);
}

private static void runTest(Class<?> clazz, boolean wireInListener) {
DataProviderListener.logs.clear();
TestNG testng = new TestNG();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package test.dataprovider.issue3236;

import static org.testng.Assert.assertEquals;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class CacheTest {

private final AtomicInteger invocationCount = new AtomicInteger(0);
private String currentUuid;

@Test(dataProvider = "dp", retryAnalyzer = MyRetry.class)
public void testMethod(String uuid) {
assertEquals(currentUuid, uuid);
if (invocationCount.get() != 2) {
throw new RuntimeException("Failed for " + uuid);
}
}

@DataProvider(name = "dp", cacheDataForTestRetries = false)
public Object[][] getData() {
invocationCount.incrementAndGet();
currentUuid = UUID.randomUUID().toString();
return new Object[][] {{currentUuid}};
}

public static class MyRetry implements IRetryAnalyzer {

private final AtomicInteger counter = new AtomicInteger(1);

@Override
public boolean retry(ITestResult result) {
return counter.getAndIncrement() != 2;
}
}
}
Loading