Skip to content
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

DBP: Restructure AgentManager and scheduler and add tests #2777

Merged

Conversation

THISISDINOSAUR
Copy link
Contributor

@THISISDINOSAUR THISISDINOSAUR commented May 14, 2024

Task/Issue URL: https://app.asana.com/0/1199230911884351/1207175016813449/f
Tech Design URL:
CC:

Description:

  1. Move all userNotification related calls and anything else unrelated to scheduling up a layer to the agent manager
  2. Removes the existing scheduler, and moves the ActivityScheduler management to a new class
  3. Make a variety of changes to scheduler behavior, such as running all the time (as long as theirs profile data), changing scheduler frequency to 20 minutes, removes status publishing
  4. Fixes us not deleting the login item when the user deleted their data
  5. As part of that, removes the dataDeleted IPC method, since it's no longer needed
  6. Reworks the agent manager and associated dependancies so it can be unit tested
  7. Adds those unit tests.

Pixels are still outstanding
But everything else should be done now (integrating with Pete's latest PR etc)

Steps to test this PR:

  1. Generally test that DBP works, but not too thoroughly since we will do that for the whole feature branch at once.

Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

@THISISDINOSAUR THISISDINOSAUR changed the base branch from feature/pir-stabilization to pete/queue-manager-and-state May 14, 2024 12:31
Copy link
Contributor

github-actions bot commented May 14, 2024

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against 7a753dc

@@ -63,12 +68,6 @@ extension DefaultDataBrokerProtectionLoginItemInterface: DataBrokerProtectionLog
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the pixels that are pending

/*
I wasn't able to import this mock from the background agent project, so I had to re-use it here.
*/
private final class PrivacyConfigurationManagingMock: PrivacyConfigurationManaging {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since various things moved to the DBP package, we can remove this :D


public func runQueuedOperations(showWebView: Bool) {
// TODO
//scheduler.runQueuedOperations(showWebView: showWebView)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pending integration with outstanding PR

@THISISDINOSAUR THISISDINOSAUR requested a review from aataraxiaa May 14, 2024 12:48
Copy link
Contributor

@aataraxiaa aataraxiaa left a comment

Choose a reason for hiding this comment

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

Nice one, looks great overall @THISISDINOSAUR. Left a few very minor suggestions and a question.

func disableLoginItem()
func enableLoginItem()
protocol DataBrokerProtectionLoginItemInterface: DataBrokerProtectionAppToAgentInterface {
func dataDeleted()
Copy link
Contributor

Choose a reason for hiding this comment

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

🥳

import BrowserServicesKit
import PixelKit

// This is to avoid exposing all the dependancies outside of the DBP package
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice solution 👍🏼

Base automatically changed from pete/queue-manager-and-state to feature/pir-stabilization May 14, 2024 14:22
…nd-scheduler

# Conflicts:
#	DuckDuckGoDBPBackgroundAgent/DataBrokerProtectionAgentManager.swift
#	LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/DataBrokerOperation.swift
#	LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift
#	LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift
#	LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueManagerTests.swift
#	LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueModeTests.swift
#	LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift
@THISISDINOSAUR
Copy link
Contributor Author

@aataraxiaa btw I've updated to integrate with your latest, and addressed all comments except for this one: #2777 (comment) (waiting to see what Juan says)
So that leaves only pixels outstanding

@jotaemepereira jotaemepereira self-requested a review May 14, 2024 19:00
Copy link
Contributor

@aataraxiaa aataraxiaa left a comment

Choose a reason for hiding this comment

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

Latest changes look good @THISISDINOSAUR. Added a comment about strange behaviour I saw this morning when testing.


extension DataBrokerProtectionAgentManager: DataBrokerProtectionAgentAppEvents {

public func profileSaved() {
Copy link
Contributor

@aataraxiaa aataraxiaa May 15, 2024

Choose a reason for hiding this comment

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

Was just testing this again this morning, and something strange was happening in that this method was never called on a profile save action. I stepped through the chain of calls and it looked like the profileSaved method of the login item was being called twice. I removed all background agents that were running, and made sure I was attached to the background process, but that didn’t solve it. Didn’t look further as I must be doing something strange. Maybe you could give it a try and let me know.

Copy link
Collaborator

@jotaemepereira jotaemepereira left a comment

Choose a reason for hiding this comment

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

@THISISDINOSAUR I’m seeing some issues when scanning. If you follow the steps you will see it:

  • Start a scan
  • Edit the profile while the scan is running (add a new name, for example)
  • Something is happening there where the profileSaved in the DataBrokerProtectionAgentManager is not being called, causing the new scans to never start.

It leaves the app in a weird state, because the scans were cancelled for some reason, but they never started again.

@THISISDINOSAUR
Copy link
Contributor Author

@THISISDINOSAUR I’m seeing some issues when scanning. If you follow the steps you will see it:

  • Start a scan
  • Edit the profile while the scan is running (add a new name, for example)
  • Something is happening there where the profileSaved in the DataBrokerProtectionAgentManager is not being called, causing the new scans to never start.

It leaves the app in a weird state, because the scans were cancelled for some reason, but they never started again.

I think this is the same issue Pete ran into and was introduced in the merge, I'm not sure what's going in yet

@THISISDINOSAUR
Copy link
Contributor Author

I figured it out, it actually happened when I added the tests, AgentManager wasn't being persisted in memory 🙄
I've also now added the pixels.
I've also added delay before each xpc call to make sure the login item had chance to start. I'm unsure if this is necessary, it depends on if the API is blocking until the login item is launched

Copy link
Contributor

@aataraxiaa aataraxiaa left a comment

Choose a reason for hiding this comment

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

Recent changes LGTM!

@jotaemepereira jotaemepereira self-requested a review May 15, 2024 18:46
Copy link
Collaborator

@jotaemepereira jotaemepereira left a comment

Choose a reason for hiding this comment

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

Worked for me 🎉

Copy link
Collaborator

@Bunn Bunn left a comment

Choose a reason for hiding this comment

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

LGTM. Tested these scenarios:

  • Scan from scratch
  • Updating user profile after scan ended
  • Updating user profile mid scan

@THISISDINOSAUR THISISDINOSAUR merged commit 1ddb5a4 into feature/pir-stabilization May 15, 2024
22 of 23 checks passed
@THISISDINOSAUR THISISDINOSAUR deleted the elle/dbp-agentmanager-and-scheduler branch May 15, 2024 21:04
THISISDINOSAUR added a commit that referenced this pull request May 22, 2024
Task/Issue URL:
https://app.asana.com/0/1199230911884351/1207338264132623/f
Tech Design URL:
https://app.asana.com/0/481882893211075/1207174884557414/f
CC:

**Description**:
This PR has the effect of mergeing four different PRs into main:
#2777
#2758
#2757
#2743
This covers significant changes to the XPC interface and how the main
app uses it, the background manager, the scheduler, and the processor.
See individual PRs for details.

There's no code changes here that haven't been reviewed separately as
part of those PRs, so it's up to you how you want to review it code
wise. The more important step at this stage is manual testing.

**Steps to test this PR**:
1. Because this is a fairly significant set of changes, we need to be as
thorough as we can in testing DBP generally works and really try to
break it. Because of this, I'm keen that anyone testing things of their
own ways to break it before trying the steps below.
2. Edit/add profile data, and before scans finish, edit it again. Scans
should start afresh, and you should see an interrupted pixel fire. Check
that you don't get a scans completed notification
3. Edit/add profile data, and before scans finish, close the app, and
reopen it. The same set of manual scans should still continue, and a
blocked pixel should fire.
4. With profile data already existing but initial scans having finished,
close the app and reopen it. Scheduled scans should run.
5. With profile data already existing, and with the app closed, launch
the background agent, scheduled scans should run
6. Edit/add profile data, put the laptop to sleep/lock it/restart it,
check that scans continue as expected.
7. Check that the background agent activity lines up with the UI, I.e.
the progress bar and when we sent the scans completed notification is
accurate

<!--
Tagging instructions
If this PR isn't ready to be merged for whatever reason it should be
marked with the `DO NOT MERGE` label (particularly if it's a draft)
If it's pending Product Review/PFR, please add the `Pending Product
Review` label.

If at any point it isn't actively being worked on/ready for
review/otherwise moving forward (besides the above PR/PFR exception)
strongly consider closing it (or not opening it in the first place). If
you decide not to close it, make sure it's labelled to make it clear the
PRs state and comment with more information.
-->

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)

---------

Co-authored-by: Pete Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants