-
Notifications
You must be signed in to change notification settings - Fork 9
Base classes for upgrade pipeline #2728
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
Merged
labkey-tchad
merged 9 commits into
release25.7-SNAPSHOT
from
25.7_fb_upgradeTestPipeline
Oct 10, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
674838f
Base classes for upgrade pipeline
labkey-tchad c059fec
Backport some useful changes
labkey-tchad 0ce7084
Cleanup imports
labkey-tchad 2592596
Update project name
labkey-tchad a4f1c8d
Reuse code
labkey-tchad f03f41c
Merge remote-tracking branch 'origin/release25.7-SNAPSHOT' into 25.7_…
labkey-tchad 411451a
Update upgrade tests
labkey-tchad c18610d
Merge remote-tracking branch 'origin/release25.7-SNAPSHOT' into 25.7_…
labkey-tchad 9741841
Add comments and fix version range check
labkey-tchad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package org.labkey.test.tests.upgrade; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
| import org.junit.Assume; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Rule; | ||
| import org.junit.rules.TestRule; | ||
| import org.junit.runner.Description; | ||
| import org.junit.runners.model.Statement; | ||
| import org.labkey.test.BaseWebDriverTest; | ||
| import org.labkey.test.TestProperties; | ||
| import org.labkey.test.util.TestLogger; | ||
| import org.labkey.test.util.Version; | ||
| import org.labkey.test.util.VersionRange; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import static org.apache.commons.lang3.StringUtils.trimToNull; | ||
|
|
||
| /** | ||
| * Base test class for tests that setup data and configure a server then verify the persistence or modification of those | ||
| * data and configurations after upgrading to a newer version of LabKey.<br> | ||
| * The {@code EariestVersion} and {@code LatestVersion} annotations can be used to skip particular tests when they are | ||
| * not relevant to the version of LabKey being upgraded from (specified in the {@code webtest.upgradePreviousVersion} | ||
| * system property).<br> | ||
| * The setup steps will be skipped if the {@code webtest.upgradeSetup} system property is set to {@code false}. | ||
| */ | ||
| public abstract class BaseUpgradeTest extends BaseWebDriverTest | ||
| { | ||
|
|
||
| protected static final boolean isUpgradeSetupPhase = TestProperties.getBooleanProperty("webtest.upgradeSetup", true); | ||
| protected static final Version previousVersion = Optional.ofNullable(trimToNull(System.getProperty("webtest.upgradePreviousVersion"))) | ||
| .map(Version::new).orElse(null); | ||
|
|
||
| @Override | ||
| protected boolean skipCleanup(boolean afterTest) | ||
| { | ||
| return afterTest || !isUpgradeSetupPhase; | ||
| } | ||
|
|
||
| @BeforeClass | ||
| public static void setupProject() throws Exception | ||
| { | ||
| BaseUpgradeTest currentTest = BaseWebDriverTest.getCurrentTest(); | ||
|
|
||
| if (isUpgradeSetupPhase) | ||
| { | ||
| currentTest.doSetup(); | ||
| } | ||
| else | ||
| { | ||
| TestLogger.info("Skipping setup for %s. Verifying upgrade.". formatted(currentTest.getClass().getSimpleName())); | ||
| } | ||
| } | ||
|
|
||
| protected abstract void doSetup() throws Exception; | ||
|
|
||
| @Rule | ||
| public final TestRule upgradeVersionCheck = new UpgradeVersionCheck(); | ||
|
|
||
| @Override | ||
| public List<String> getAssociatedModules() | ||
| { | ||
| return Arrays.asList(); | ||
| } | ||
|
|
||
| /** | ||
| * Annotates test methods that should only run when upgrading from particular LabKey versions, as specified in | ||
| * {@code webtest.upgradePreviousVersion}.<br> | ||
| * Specifies the earliest version of the test class that performed the required setup for the annotated method. | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.METHOD}) | ||
| protected @interface EariestVersion { | ||
| String value(); | ||
| } | ||
|
|
||
| /** | ||
| * Annotates test methods that should only run when upgrading from particular LabKey versions, as specified in | ||
| * {@code webtest.upgradePreviousVersion}.<br> | ||
| * Specifies the latest version of the test class that performed the required setup for the annotated method. | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.METHOD}) | ||
| protected @interface LatestVersion { | ||
| String value(); | ||
| } | ||
|
|
||
| private static class UpgradeVersionCheck implements TestRule | ||
| { | ||
|
|
||
| @Override | ||
| public @NotNull Statement apply(Statement base, Description description) | ||
| { | ||
| String eariestVersion = Optional.ofNullable(description.getAnnotation(EariestVersion.class)) | ||
| .map(EariestVersion::value).orElse(null); | ||
| String latestVersion = Optional.ofNullable(description.getAnnotation(LatestVersion.class)) | ||
| .map(LatestVersion::value).orElse(null); | ||
|
|
||
| if (isUpgradeSetupPhase || previousVersion == null || (eariestVersion == null && latestVersion == null)) | ||
| { | ||
| return base; // Run the test normally | ||
| } | ||
|
|
||
| return new Statement() | ||
| { | ||
| @Override | ||
| public void evaluate() throws Throwable | ||
| { | ||
| Assume.assumeTrue("Test doesn't support upgrading from version: " + previousVersion, | ||
| VersionRange.versionRange(eariestVersion, latestVersion).contains(previousVersion) | ||
| ); | ||
| base.evaluate(); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package org.labkey.test.tests.upgrade; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.labkey.remoteapi.CommandException; | ||
| import org.labkey.remoteapi.Connection; | ||
| import org.labkey.remoteapi.query.SelectRowsCommand; | ||
| import org.labkey.test.params.FieldInfo; | ||
| import org.labkey.test.params.experiment.SampleTypeDefinition; | ||
| import org.labkey.test.util.TestUser; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.labkey.test.util.PermissionsHelper.READER_ROLE; | ||
|
|
||
| @Category({}) | ||
| public class BasicUpgradeTest extends BaseUpgradeTest | ||
| { | ||
| private static final TestUser USER = new TestUser("basic_upgrade_reader@basicupgradetest.test"); | ||
labkey-tchad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private static final String SAMPLE_TYPE = "UpgradeTestSamples"; | ||
|
|
||
| private static final FieldInfo STR_COL = new FieldInfo("String Col1"); | ||
|
|
||
| @Override | ||
| protected void doCleanup(boolean afterTest) | ||
| { | ||
| _containerHelper.deleteProject(getProjectName(), afterTest); | ||
| _userHelper.deleteUsers(afterTest, USER); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doSetup() throws Exception | ||
| { | ||
| _containerHelper.createProject(getProjectName(), null); | ||
| USER.create(this); | ||
| USER.setInitialPassword(); | ||
| USER.addPermission(READER_ROLE, getProjectName()); | ||
|
|
||
| new SampleTypeDefinition(SAMPLE_TYPE) | ||
| .setFields(List.of(STR_COL.getFieldDefinition())) | ||
| .create(createDefaultConnection(), getProjectName()) | ||
| .insertRows(createDefaultConnection(), List.of(Map.of( | ||
| "Name", "S-1", | ||
| STR_COL.getName(), "Test String Value" | ||
| )) ); | ||
| } | ||
|
|
||
| @Before | ||
| public void preTest() | ||
| { | ||
| USER.load(this); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSampleRowsExist() throws Exception | ||
| { | ||
| // Use primary user to verify data | ||
| queryData(createDefaultConnection()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUserPassword() throws Exception | ||
| { | ||
| // Use password authentication for USER | ||
| queryData(USER.getUserConnection()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUserPermissions() throws Exception | ||
| { | ||
| // Impersonate to test USER's permission level | ||
| queryData(createDefaultConnection().impersonate(USER.getEmail())); | ||
| } | ||
|
|
||
| private void queryData(Connection connection) throws IOException, CommandException | ||
| { | ||
| List<Map<String, Object>> rows = new SelectRowsCommand("samples", SAMPLE_TYPE) | ||
| .execute(connection, getProjectName()) | ||
| .getRows(); | ||
| assertFalse("Expected at least one row", rows.isEmpty()); | ||
| } | ||
|
|
||
labkey-tchad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| protected String getProjectName() | ||
| { | ||
| return getClass().getSimpleName() + " Project"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a small comment for these to avoid any confusion.
Does LatestVersion == current version (in develop or current release branch)?