{"action":"created","issue":{"url":"https://api.github.com/repos/danthorpe/Operations/issues/123","labels_url":"https://api.github.com/repos/danthorpe/Operations/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/danthorpe/Operations/issues/123/comments","events_url":"https://api.github.com/repos/danthorpe/Operations/issues/123/events","html_url":"https://github.com/danthorpe/Operations/issues/123","id":121624176,"number":123,"title":"NSOperation's completionBlock is called twice.","user":{"login":"difujia","id":2255369,"avatar_url":"https://avatars.githubusercontent.com/u/2255369?v=3","gravatar_id":"","url":"https://api.github.com/users/difujia","html_url":"https://github.com/difujia","followers_url":"https://api.github.com/users/difujia/followers","following_url":"https://api.github.com/users/difujia/following{/other_user}","gists_url":"https://api.github.com/users/difujia/gists{/gist_id}","starred_url":"https://api.github.com/users/difujia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/difujia/subscriptions","organizations_url":"https://api.github.com/users/difujia/orgs","repos_url":"https://api.github.com/users/difujia/repos","events_url":"https://api.github.com/users/difujia/events{/privacy}","received_events_url":"https://api.github.com/users/difujia/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/danthorpe/Operations/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-12-11T02:42:50Z","updated_at":"2015-12-14T14:29:55Z","closed_at":null,"body":"Try the following test. \r\n```swift\r\nfunc testCompletionBlock() {\r\n    let queue = OperationQueue()\r\n    let blockOp = BlockOperation()\r\n    let exp = expectationWithDescription(\"Block finished\")\r\n    blockOp.addCompletionBlock {\r\n        exp.fulfill()\r\n    }\r\n    queue.addOperation(blockOp)\r\n    waitForExpectationsWithTimeout(5, handler: nil)\r\n}\r\n```\r\nThen the test runner will log:\r\n>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'API violation - multiple calls made to -[XCTestExpectation fulfill] for Block finished.'\r\n\r\nThe same error appear even if I set the `completionBlock` directly, which I think make no difference when only one completionBlock exists.\r\n\r\n*Discussion* Xcode would not always stop the test as the error pops up, I think this is due to a race condition that the second call of `fulfill()` may happen either before or after `waitForExpectationsWithTimeout` has seen the effect of the first call (in case of after, the test has finished running and succeeded). Anyway, this is probably irrelevant of the issue. Isn't the `completionBlock` guaranteed to execute only once by Foundation framework?"},"comment":{"url":"https://api.github.com/repos/danthorpe/Operations/issues/comments/164451413","html_url":"https://github.com/danthorpe/Operations/issues/123#issuecomment-164451413","issue_url":"https://api.github.com/repos/danthorpe/Operations/issues/123","id":164451413,"user":{"login":"danthorpe","id":309420,"avatar_url":"https://avatars.githubusercontent.com/u/309420?v=3","gravatar_id":"","url":"https://api.github.com/users/danthorpe","html_url":"https://github.com/danthorpe","followers_url":"https://api.github.com/users/danthorpe/followers","following_url":"https://api.github.com/users/danthorpe/following{/other_user}","gists_url":"https://api.github.com/users/danthorpe/gists{/gist_id}","starred_url":"https://api.github.com/users/danthorpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danthorpe/subscriptions","organizations_url":"https://api.github.com/users/danthorpe/orgs","repos_url":"https://api.github.com/users/danthorpe/repos","events_url":"https://api.github.com/users/danthorpe/events{/privacy}","received_events_url":"https://api.github.com/users/danthorpe/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T14:29:55Z","updated_at":"2015-12-14T14:29:55Z","body":"@difujia @kevinbrewster proposed fix: https://github.com/danthorpe/Operations/commit/689c29e3822533e806ea495fd2d28992b77df5e8 has been merged into `development`. Will leave this issue open until either of you can confirm that the completion block is no longer called twice. My [test for this](https://github.com/danthorpe/Operations/blob/development/Tests/Core/OperationTests.swift#L242) passes."}}