Skip to content
Merged
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 @@ -23,6 +23,8 @@
import io.dropwizard.configuration.YamlConfigurationFactory;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.jersey.validation.Validators;
import io.dropwizard.lifecycle.JettyManaged;
import io.dropwizard.lifecycle.Managed;
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import jakarta.validation.Validator;
Expand All @@ -35,6 +37,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.hc.client5.http.auth.AuthScope;
Expand Down Expand Up @@ -1179,6 +1182,27 @@ public static int getApplicationPort() {
return APP.getLocalPort();
}

/**
* Returns the application's registered {@link Managed} of the given type, if there is one.
*
* <p>Dropwizard wraps every managed object in a {@link JettyManaged}, so the instance the
* application built is only reachable by unwrapping the lifecycle objects. Tests use this to
* reach always-on background workers — typically to pause one for the duration of a class whose
* assertions would otherwise race it on a shared table.
*/
public static <T extends Managed> Optional<T> findManagedObject(Class<T> type) {
if (APP == null) {
throw new IllegalStateException(
"Application is not running. Ensure TestSuiteBootstrap has initialized.");
}
return APP.getEnvironment().lifecycle().getManagedObjects().stream()
.filter(JettyManaged.class::isInstance)
.map(lifeCycle -> ((JettyManaged) lifeCycle).getManaged())
.filter(type::isInstance)
.map(type::cast)
.findFirst();
}

/**
* Returns the admin port for accessing admin endpoints like /prometheus.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import java.util.Set;
import java.util.UUID;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openmetadata.it.bootstrap.TestSuiteBootstrap;
import org.openmetadata.it.factories.DatabaseSchemaTestFactory;
import org.openmetadata.it.factories.DatabaseServiceTestFactory;
import org.openmetadata.it.factories.TableTestFactory;
Expand All @@ -41,13 +43,51 @@ class SearchIndexRetryQueueIT {
private static CollectionDAO collectionDAO;
private static SearchIndexRetryQueueDAO retryQueueDAO;
private static SearchRepository searchRepository;
private static SearchIndexRetryWorker applicationRetryWorker;

@BeforeAll
static void setupAll() {
SdkClients.adminClient();
collectionDAO = Entity.getCollectionDAO();
retryQueueDAO = collectionDAO.searchIndexRetryQueueDAO();
searchRepository = Entity.getSearchRepository();
applicationRetryWorker = pauseApplicationRetryWorker();
}

@AfterAll
static void resumeApplicationRetryWorker() {
if (applicationRetryWorker != null) {
applicationRetryWorker.start();
applicationRetryWorker = null;
}
}

/**
* Pauses the always-on {@link SearchIndexRetryWorker} the application registers at startup and
* returns it, so {@link #resumeApplicationRetryWorker()} can put it back.
*
* <p>That worker runs four threads that poll the shared {@code search_index_retry_queue} table
* every five seconds and claim <i>every</i> row sitting in PENDING, PENDING_RETRY_1 or
* PENDING_RETRY_2 — flipping it to IN_PROGRESS, then deleting it once processed. The tests below
* write rows in exactly those statuses and read them straight back, so the worker takes them in
* the window between the write and the read and the read finds nothing:
* {@code java.util.NoSuchElementException: No value present}.
*
* <p>Nothing here needs it running: the worker tests construct and start their own worker, and
* the DAO-level tests want no worker at all. Pausing it for the duration of the class is what
* makes them deterministic instead of timing-dependent.
*/
private static SearchIndexRetryWorker pauseApplicationRetryWorker() {
SearchIndexRetryWorker worker =
TestSuiteBootstrap.findManagedObject(SearchIndexRetryWorker.class)
.orElseThrow(
() ->
new IllegalStateException(
"The application registered no SearchIndexRetryWorker. These tests pause "
+ "it to keep their assertions deterministic; without it they race the "
+ "worker for rows in the shared retry queue."));
worker.stop();
return worker;
}

@BeforeEach
Expand Down Expand Up @@ -914,11 +954,11 @@ void testEnqueuePreservesErrorDetailInFailureReason(TestNamespace ns) {
// ---------------------------------------------------------------------------

/**
* A row enqueued for an unresolvable/deleted entity is "handled" once ANY worker (this test's
* worker or the always-on application worker sharing the global queue) has touched it: the row is
* either gone (the success path after remove-stale) or no longer sitting untouched in its initial
* PENDING state. The row counts as untouched only while it is still PENDING with retryCount 0 and
* no claimedAt — so this still fails if no worker ever processes the row.
* A row enqueued for an unresolvable/deleted entity is "handled" once the worker this test
* started has touched it: the row is either gone (the success path after remove-stale) or no
* longer sitting untouched in its initial PENDING state. The row counts as untouched only while
* it is still PENDING with retryCount 0 and no claimedAt — so this still fails if no worker ever
* processes the row.
*/
private boolean isHandledByAnyWorker(String entityId) {
SearchIndexRetryRecord record =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ for (const scenario of CLAIM_SCENARIOS) {
await test.step('Authenticate at Okta', async () => {
await page.goto('/signin');

const signInButton = page.locator('button.signin-button');
const signInButton = page.getByTestId('sso-login-button');

await expect(signInButton).toBeVisible();
await signInButton.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
const completeOidcSelfSignup = async (page: Page): Promise<void> => {
await page.goto('/');

const ssoButton = page.locator('button.signin-button');
const ssoButton = page.getByTestId('sso-login-button');
await ssoButton.waitFor({ state: 'visible', timeout: 30000 });
await ssoButton.click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test.describe('SSO Session Limit', { tag: SESSION_LIMIT_TAGS }, () => {
// not raise the "session has timed out" banner, so assert the logged-out state.
await evicted.reload();
await evicted.waitForURL('**/signin', { timeout: 30_000 });
await expect(evicted.locator('button.signin-button')).toBeVisible();
await expect(evicted.getByTestId('sso-login-button')).toBeVisible();

// The newest session is within the cap and stays authenticated.
await survivor.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ export const keycloakOidcPublicProviderFixture: SsoProviderFixture = {
if (signupAppeared) {
// displayName is required; the SPA pre-fills it from token claims but
// the KC realm's user has no given_name claim, so fill deterministically.
const fullNameInput = page.getByTestId('full-name-input');
// #33575 migrated the signup screen to core-components, which puts the
// test id on the react-aria wrapper (`data-input-wrapper`) rather than the
// control -- filling it throws "Element is not an <input>". Reach the
// control the way the rest of the corpus does for these wrappers.
const fullNameInput = page
.getByTestId('full-name-input')
.locator('input');
const currentName = await fullNameInput.inputValue().catch(() => '');
if (!currentName) {
await fullNameInput.fill('Azure Saml');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const loginViaSso = async (
): Promise<void> => {
await page.goto('/signin');

const signInButton = page.locator('button.signin-button');
const signInButton = page.getByTestId('sso-login-button');

await expect(signInButton).toBeVisible();
await signInButton.click();
Expand Down
Loading