<commit_before>//
//  TimeoutTests.swift
//  Channels
//
//  Created by <NAME> on 2015-06-13.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import XCTest

@testable import Channels

class TimeoutTests: XCTestCase
{
  let delay: Int64 = 50_000

  func testTimeout()
  {
    let start = mach_absolute_time()

    let time1 = dispatch_time(DISPATCH_TIME_NOW, delay)
    let rx1 = Timeout(time1)
    XCTAssert(rx1.isClosed == false)
    <-rx1
    let time2 = dispatch_time(DISPATCH_TIME_NOW, 0)
    XCTAssert(rx1.isClosed)
    XCTAssert(time1 <= time2)

    XCTAssert(rx1.isEmpty)

    let rx2 = Timeout(delay: delay)
    XCTAssert(rx2.isClosed == false)
    _ = rx2.receive()
    XCTAssert(rx2.isClosed)

    let rx3 = Receiver.Wrap(Timeout())
    <-rx3
    rx3.close()
    XCTAssert(rx3.isClosed)

    let dt = mach_absolute_time() - start
    XCTAssert(dt > numericCast(2*delay))
  }

  func testSelectTimeout()
  {
    let count = 10
    let channels = (0..<count).map { _ in Channel<Int>.Make() }<commit_msg>Timeout test tweak<commit_after>//
//  TimeoutTests.swift
//  Channels
//
//  Created by <NAME> on 2015-06-13.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import XCTest

@testable import Channels

class TimeoutTests: XCTestCase
{
  let delay: Int64 = 50_000

  func testTimeout()
  {
    let start = mach_absolute_time()

    let time1 = dispatch_time(DISPATCH_TIME_NOW, delay)
    let rx1 = Timeout(time1)
    XCTAssert(rx1.isEmpty)
    XCTAssert(rx1.isClosed == false)
    <-rx1
    let time2 = dispatch_time(DISPATCH_TIME_NOW, 0)
    XCTAssert(rx1.isClosed)
    XCTAssert(time1 <= time2)

    let rx2 = Timeout(delay: delay)
    XCTAssert(rx2.isClosed == false)
    _ = rx2.receive()
    XCTAssert(rx2.isClosed)

    let rx3 = Receiver.Wrap(Timeout())
    XCTAssert(rx3.isEmpty)
    <-rx3
    rx3.close()
    XCTAssert(rx3.isClosed)

    let dt = mach_absolute_time() - start
    XCTAssert(dt > numericCast(2*delay))
  }

  func testSelectTimeout()
  {
    let count = 10
    let channels = (0..<count).map { _ in Channel<Int>.Make() }
{'fraction_non_alphanumeric': 0.1213707758210376, 'fraction_numerical': 0.0404569252736792, 'mean_word_length': 3.0268199233716473, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, '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': '3605858', 'n_tokens_mistral': 838, 'n_tokens_neox': 761, 'n_words': 167}