Skip to content

Stabilize editor settings response tests - #26405

Merged
crazytonyli merged 1 commit into
trunkfrom
bugfix/flaky-editor-settings-service-test
Nov 16, 2026
Merged

crazytonyli merged 1 commit into
trunkfrom
bugfix/flaky-editor-settings-service-test

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

No description provided.

@dangermattic

Copy link
Copy Markdown
Collaborator
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@crazytonyli
crazytonyli requested a review from jkmassel November 16, 2026 01:13
@crazytonyli crazytonyli added this to the 27.5 milestone Nov 16, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review November 16, 2026 01:13
Comment on lines +104 to +107
waitForEditorUpdate(to: .gutenberg, blogs: blogs) {
service.migrateGlobalSettingToRemote(isGutenbergEnabled: true)
remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:

This call site uses the migrateGlobalSetting(to:response:) helper suggested at line 139.

Not blocking: apply this together with the other two suggestions in one batch ("Add suggestion to batch"). Each one depends on the others, so applying only some of them breaks the build.

Suggested change
waitForEditorUpdate(to: .gutenberg, blogs: blogs) {
service.migrateGlobalSettingToRemote(isGutenbergEnabled: true)
remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
}
migrateGlobalSetting(to: .gutenberg, response: response)

Comment on lines +126 to +129
waitForEditorUpdate(to: .aztec, blogs: blogs) {
service.migrateGlobalSettingToRemote(isGutenbergEnabled: false)
remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:

This call site uses the migrateGlobalSetting(to:response:) helper suggested at line 139.

Not blocking: apply this together with the other two suggestions in one batch ("Add suggestion to batch"). Each one depends on the others, so applying only some of them breaks the build.

Suggested change
waitForEditorUpdate(to: .aztec, blogs: blogs) {
service.migrateGlobalSettingToRemote(isGutenbergEnabled: false)
remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
}
migrateGlobalSetting(to: .aztec, response: response)

Comment on lines +139 to 157
private func waitForEditorUpdate(to editor: MobileEditor, blogs: [Blog], update: () -> Void) {
let editorsUpdated = expectation(description: "Editors updated to \(editor.rawValue.capitalized)")
var didFulfill = false
let observer = NotificationCenter.default.addObserver(
forName: .NSManagedObjectContextObjectsDidChange,
object: mainContext,
queue: nil
) { _ in
if blogs.allSatisfy({ $0.editor == .aztec && !$0.isGutenbergEnabled }) {
editorsUpdated.fulfill()
guard !didFulfill, blogs.allSatisfy({ $0.editor == editor }) else {
return
}
didFulfill = true
editorsUpdated.fulfill()
}
defer { NotificationCenter.default.removeObserver(observer) }

service.migrateGlobalSettingToRemote(isGutenbergEnabled: false)
remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())

update()
wait(for: [editorsUpdated], timeout: 2)
NotificationCenter.default.removeObserver(observer)
blogs.forEach { blog in
XCTAssertFalse(blog.isGutenbergEnabled)
XCTAssertEqual(blog.editor, .aztec)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:

migrateGlobalSettingToRemote already takes an onSuccess closure (EditorSettingsService.swift:66). It runs on the main thread after the save, and the sites are already updated by then. So the notification observer and the didFulfill guard aren't needed.

Checked locally with all three suggestions applied:

  • 200 runs of EditorSettingsServiceTest with every CPU core busy: 0 failures.
  • Service changed to ignore the server response: both tests still fail. They fail at the assertions in about 0.04 s, without waiting out the 2 s timeout.
  • swift-format leaves the file unchanged, and SwiftLint reports nothing.

Not blocking: apply this together with the other two suggestions in one batch ("Add suggestion to batch"). Each one depends on the others, so applying only some of them breaks the build.

Suggested change
private func waitForEditorUpdate(to editor: MobileEditor, blogs: [Blog], update: () -> Void) {
let editorsUpdated = expectation(description: "Editors updated to \(editor.rawValue.capitalized)")
var didFulfill = false
let observer = NotificationCenter.default.addObserver(
forName: .NSManagedObjectContextObjectsDidChange,
object: mainContext,
queue: nil
) { _ in
if blogs.allSatisfy({ $0.editor == .aztec && !$0.isGutenbergEnabled }) {
editorsUpdated.fulfill()
guard !didFulfill, blogs.allSatisfy({ $0.editor == editor }) else {
return
}
didFulfill = true
editorsUpdated.fulfill()
}
defer { NotificationCenter.default.removeObserver(observer) }
service.migrateGlobalSettingToRemote(isGutenbergEnabled: false)
remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
update()
wait(for: [editorsUpdated], timeout: 2)
NotificationCenter.default.removeObserver(observer)
blogs.forEach { blog in
XCTAssertFalse(blog.isGutenbergEnabled)
XCTAssertEqual(blog.editor, .aztec)
}
}
private func migrateGlobalSetting(to editor: MobileEditor, response: [String: String]) {
let migrated = expectation(description: "Editors updated to \(editor.rawValue.capitalized)")
service.migrateGlobalSettingToRemote(isGutenbergEnabled: editor == .gutenberg) {
migrated.fulfill()
}
remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
wait(for: [migrated], timeout: 2)
}

@crazytonyli
crazytonyli added this pull request to the merge queue Nov 16, 2026
Merged via the queue into trunk with commit 61a9d99 Nov 16, 2026
23 checks passed
@crazytonyli
crazytonyli deleted the bugfix/flaky-editor-settings-service-test branch November 16, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants