Repository navigation
Stabilize editor settings response tests - #26405
Conversation
Generated by 🚫 Danger |
| waitForEditorUpdate(to: .gutenberg, blogs: blogs) { | ||
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: true) | ||
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | ||
| } |
There was a problem hiding this comment.
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.
| waitForEditorUpdate(to: .gutenberg, blogs: blogs) { | |
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: true) | |
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | |
| } | |
| migrateGlobalSetting(to: .gutenberg, response: response) |
| waitForEditorUpdate(to: .aztec, blogs: blogs) { | ||
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: false) | ||
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | ||
| } |
There was a problem hiding this comment.
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.
| waitForEditorUpdate(to: .aztec, blogs: blogs) { | |
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: false) | |
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | |
| } | |
| migrateGlobalSetting(to: .aztec, response: response) |
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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
EditorSettingsServiceTestwith 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.
| 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) | |
| } |
No description provided.