         assertClientsHaveGUIDsFromStorage(tabs, expected: ["abcdefghijkl"])
 
         // Tell the sync manager that "clients" has changed syncID.
-        let e = MockEngineStateChanges()
-        e.collections.append("clients")
+        let engine = MockEngineStateChanges()
+        engine.collections.append("clients")
 
-        _ = profile.tabs.reopenIfClosed()
+        let error = profile.tabs.reopenIfClosed()
+        if let error = error {
+            XCTFail("Could not reopen tabs, failed with error \(error.description)")
+            return
+        }
 
-        XCTAssertTrue(profile.peekSyncManager.takeActionsOnEngineStateChanges(e).value.isSuccess)
+        XCTAssertTrue(profile.peekSyncManager.takeActionsOnEngineStateChanges(engine).value.isSuccess)
 
         // We threw away the command.
-        XCTAssertTrue(e.clearWasCalled)
+        XCTAssertEqual(engine.clearLocalCommandsCount, 1, "Clear local commands was called once")
 
         // And now we have no local clients.
         let empty = tabs.getClients().value.successValue

import UIKit

import XCTest

class MockBrowserProfile: BrowserProfile {
    var peekSyncManager: BrowserSyncManager {
        return self.syncManager as! BrowserSyncManager
    }

    var peekTabs: SQLiteRemoteClientsAndTabs {
        return self.remoteClientsAndTabs as! SQLiteRemoteClientsAndTabs
    }
}

class MockEngineStateChanges: EngineStateChanges {
    var collections: [String] = []
    var enabled: [String] = []
    var disabled: [String] = []
    var clearWasCalled: Bool = false

    func collectionsThatNeedLocalReset() -> [String] {
        return self.collections
    }

    func enginesEnabled() -> [String] {
        return self.enabled
    }

    func enginesDisabled() -> [String] {
        return self.disabled
    }

    func clearLocalCommands() {
        clearWasCalled = true
    }
}

func assertClientsHaveGUIDsFromStorage(_ storage: RemoteClientsAndTabs, expected: [GUID]) {
    let recs = storage.getClients().value.successValue
    XCTAssertNotNil(recs)
    XCTAssertEqual(expected, recs!.map { $0.guid! })
}

class ResetTests: XCTestCase {
    func testResetting() {

        XCTAssertEqual(empty!, [])
    }
}

// MARK: - Helper methods
extension ResetTests {
    func assertClientsHaveGUIDsFromStorage(_ storage: RemoteClientsAndTabs, expected: [GUID]) {
        let recs = storage.getClients().value.successValue
        XCTAssertNotNil(recs)
        XCTAssertEqual(expected, recs!.map { $0.guid! })
    }
}

// MARK: - MockBrowserProfile
class MockBrowserProfile: BrowserProfile {
    var peekSyncManager: BrowserSyncManager {
        return self.syncManager as! BrowserSyncManager
    }

    var peekTabs: SQLiteRemoteClientsAndTabs {
        return self.remoteClientsAndTabs as! SQLiteRemoteClientsAndTabs
    }
}

// MARK: - MockEngineStateChanges
class MockEngineStateChanges: EngineStateChanges {
    var collections: [String] = []
    var enabled: [String] = []
    var disabled: [String] = []
    var clearLocalCommandsCount = 0

    func collectionsThatNeedLocalReset() -> [String] {
        return self.collections
    }

    func enginesEnabled() -> [String] {
        return self.enabled
    }

    func enginesDisabled() -> [String] {
        return self.disabled
    }

    func clearLocalCommands() {
        clearLocalCommandsCount += 1
    }
}
