Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent duplicate startup work scheduling #217

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
MihaiCristianCondrea merged 1 commit into main from codex/mock-workmanager-in-startup-tests
Sep 16, 2025

Conversation

@MihaiCristianCondrea
Copy link
Owner

@MihaiCristianCondrea MihaiCristianCondrea commented Sep 16, 2025

Summary

  • guard StartupInitializer.schedule so startup work only enqueues once per app launch
  • add a visible-for-testing reset hook to clear scheduling state for unit tests
  • expand startup tests to verify the unique work request and repeated scheduling behaviour

Testing

  • ./gradlew test (fails: Android SDK not installed in environment)

https://chatgpt.com/codex/tasks/task_e_68c976429144832d99e05802da6b1aec

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 30 to 38
public static void schedule(@NonNull Context context) {
if (!HAS_SCHEDULED.compareAndSet(false, true)) {
return;
}

OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(
StartupWorker.class).build();
WorkManager.getInstance(context).enqueueUniqueWork(
WORK_NAME, ExistingWorkPolicy.KEEP, workRequest);
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Guard boolean before enqueue causes permanent skip on failure

The new HAS_SCHEDULED.compareAndSet(false, true) runs before WorkManager.getInstance(context).enqueueUniqueWork(...). If getInstance throws (e.g. WorkManager not yet initialized in this process, a documented possibility) the method exits with the flag stuck at true. Subsequent retries in the same process will return immediately without scheduling the startup work, so initialization never happens. Consider setting the flag only after the enqueue succeeds or resetting it in a catch block to preserve retry behaviour when the first attempt fails.

Useful? React with 👍 / 👎.

@MihaiCristianCondrea MihaiCristianCondrea merged commit d557c4b into main Sep 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chatgpt-codex-connector chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] left review comments

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /