<commit_before>//
//  PSOperationsAppForTestsTests.swift
//  PSOperationsAppForTestsTests
//
//  Created by <NAME> on 1/11/16.
//  Copyright © 2016 Pluralsight. All rights reserved.
//

import XCTest
import PSOperations

class PSOperationsAppForTestsTests: XCTestCase {
    
    /*
     This test only exhibits the problem when run in an app container, thus, it is part of a test suite that is
     part of an application. When you have many (less than the tested amount) operations that have dependencies 
     often a crash occurs when all operations in the dependency chain are completed.
     This problem is not limited to PSOperations. If you adapt this test to use NSOperationQueue and NSBlockOperation 
     (or some other NSOperation, doesn't matter) This same crash will occur. While meeting expectations is important
     the real test is whether or not it crashes when the last operation finishes
    */
    func testDependantOpsCrash() {
        let queue = PSOperations.OperationQueue()
        let opcount = 10_000
        var ops: [PSOperations.Operation] = []
        for _ in 0..<opcount {
            
            let exp = expectation(description: "block should finish")
            
            let block = PSOperations.BlockOperation {
                (finish: () -> Void) in
//                NSLog("op: \(i): opcount: queue: \(queue.operationCount)")
                exp.fulfill()
                finish()
            }
            <commit_msg>Lower op count on test.<commit_after>//
//  PSOperationsAppForTestsTests.swift
//  PSOperationsAppForTestsTests
//
//  Created by <NAME> on 1/11/16.
//  Copyright © 2016 Pluralsight. All rights reserved.
//

import XCTest
import PSOperations

class PSOperationsAppForTestsTests: XCTestCase {
    
    /*
     This test only exhibits the problem when run in an app container, thus, it is part of a test suite that is
     part of an application. When you have many (less than the tested amount) operations that have dependencies 
     often a crash occurs when all operations in the dependency chain are completed.
     This problem is not limited to PSOperations. If you adapt this test to use NSOperationQueue and NSBlockOperation 
     (or some other NSOperation, doesn't matter) This same crash will occur. While meeting expectations is important
     the real test is whether or not it crashes when the last operation finishes
    */
    func testDependantOpsCrash() {
        let queue = PSOperations.OperationQueue()
        let opcount = 5_000
        var ops: [PSOperations.Operation] = []
        for _ in 0..<opcount {
            
            let exp = expectation(description: "block should finish")
            
            let block = PSOperations.BlockOperation {
                (finish: () -> Void) in
//                NSLog("op: \(i): opcount: queue: \(queue.operationCount)")
                exp.fulfill()
                finish()
            }
            
{'fraction_non_alphanumeric': 0.06960950764006792, 'fraction_numerical': 0.009847198641765705, 'mean_word_length': 2.332579185520362, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3226848', 'n_tokens_mistral': 768, 'n_tokens_neox': 746, 'n_words': 312}