Skip to content

Commit

Permalink
Reduce test compile times.
Browse files Browse the repository at this point in the history
I noticed that the tests were taking quite a while to compile.

Using the "-warn-long-expression-type-checking" flag, I measured the
compile time of the test project. The total of types over 100ms was
around 27 seconds before this change and around 25 seconds after (on my
build configuration), so it shaves off a few seconds there.

I also took the opportunity to reduce the number of attempted threads in
the URL test from 640 to 10. There isn't much value add in going above
the number of cores we're going to find on most machines, and that
dramatically reduces the run time of that test.
  • Loading branch information
parkera committed Dec 3, 2017
1 parent 08afbe6 commit 9431ced
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 20 deletions.
10 changes: 7 additions & 3 deletions TestFoundation/TestDecimal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ class TestDecimal: XCTestCase {
}

func test_ExplicitConstruction() {
let reserved: UInt32 = (1<<18 as UInt32) + (1<<17 as UInt32) + 1
let mantissa: (UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16) = (6, 7, 8, 9, 10, 11, 12, 13)
var explicit = Decimal(
_exponent: 0x17f,
_length: 0xff,
_isNegative: 3,
_isCompact: 4,
_reserved: 1<<18 + 1<<17 + 1,
_mantissa: (6, 7, 8, 9, 10, 11, 12, 13)
_reserved: reserved,
_mantissa: mantissa
)
XCTAssertEqual(0x7f, explicit._exponent)
XCTAssertEqual(0x7f, explicit.exponent)
Expand All @@ -195,7 +197,9 @@ class TestDecimal: XCTestCase {
XCTAssertEqual(FloatingPointSign.minus, explicit.sign)
XCTAssertTrue(explicit.isSignMinus)
XCTAssertEqual(0, explicit._isCompact)
XCTAssertEqual(UInt32(1<<17 + 1), explicit._reserved)
let i = 1 << 17 + 1
let expectedReserved: UInt32 = UInt32(i)
XCTAssertEqual(expectedReserved, explicit._reserved)
let (m0, m1, m2, m3, m4, m5, m6, m7) = explicit._mantissa
XCTAssertEqual(6, m0)
XCTAssertEqual(7, m1)
Expand Down
5 changes: 4 additions & 1 deletion TestFoundation/TestNSAttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ fileprivate extension TestNSAttributedString {

fileprivate func describe(attrs: [NSAttributedStringKey : Any]) -> String {
if attrs.count > 0 {
return "[" + attrs.map({ "\($0.rawValue):\($1)" }).sorted(by: { $0 < $1 }).joined(separator: ",") + "]"
let mapped: [String] = attrs.map({ "\($0.rawValue):\($1)" })
let sorted: [String] = mapped.sorted(by: { $0 < $1 })
let joined: String = sorted.joined(separator: ",")
return "[" + joined + "]"
} else {
return "[:]"
}
Expand Down
15 changes: 9 additions & 6 deletions TestFoundation/TestNSKeyedArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,15 @@ class TestNSKeyedArchiver : XCTestCase {
}

func test_archive_mutable_dictionary() {
let mdictionary = NSMutableDictionary(dictionary: [
"one": NSNumber(value: Int(1)),
"two": NSNumber(value: Int(2)),
"three": NSNumber(value: Int(3)),
])

let one: NSNumber = NSNumber(value: Int(1))
let two: NSNumber = NSNumber(value: Int(2))
let three: NSNumber = NSNumber(value: Int(3))
let dict: [String : Any] = [
"one": one,
"two": two,
"three": three,
]
let mdictionary = NSMutableDictionary(dictionary: dict)
test_archive(mdictionary)
}

Expand Down
8 changes: 6 additions & 2 deletions TestFoundation/TestNSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,12 @@ class TestNSNumber : XCTestCase {
XCTAssertTrue(NSNumber(value: true) == NSNumber(value: Int8(1)))
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: false))
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Int8(-1)))
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Float(1.01)))
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Double(1234.56)))
let f: Float = 1.01
let floatNum = NSNumber(value: f)
XCTAssertTrue(NSNumber(value: true) != floatNum)
let d: Double = 1234.56
let doubleNum = NSNumber(value: d)
XCTAssertTrue(NSNumber(value: true) != doubleNum)
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: 2))
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Int.max))
XCTAssertTrue(NSNumber(value: false) == NSNumber(value: Bool(false)))
Expand Down
3 changes: 2 additions & 1 deletion TestFoundation/TestNumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class TestNumberFormatter: XCTestCase {
let noPlusString = numberFormatter.string(from: -0.420)
XCTAssertNotNil(noPlusString)
if let fmt = noPlusString {
XCTAssertFalse(fmt.contains(sign), "Expected format of -0.420 (-4.2E-1) shouldn't have a plus sign which was set as \(sign)")
let contains: Bool = fmt.contains(sign)
XCTAssertFalse(contains, "Expected format of -0.420 (-4.2E-1) shouldn't have a plus sign which was set as \(sign)")
}
}

Expand Down
6 changes: 1 addition & 5 deletions TestFoundation/TestURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,8 @@ class TestURLSession : LoopbackServerTest {
}

func test_concurrentRequests() {
#if os(Android)
// "10 tasks ought to be enough for anybody"
let tasks = 10
XCTFail("640 tasks causes other tests to fail on Android")
#else
let tasks = 640
#endif
let syncQ = dispatchQueueMake("test_dataTaskWithURL.syncQ")
var dataTasks: [DataTask] = []
let g = dispatchGroupMake()
Expand Down
5 changes: 4 additions & 1 deletion TestFoundation/TestXMLDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ class TestXMLDocument : XCTestCase {
let otherDoc = XMLDocument(rootElement: XMLElement(name: "Bar"))
otherDoc.rootElement()?.namespaces = [XMLNode.namespace(withName: "R", stringValue: "http://example.com/rnamespace") as! XMLNode, XMLNode.namespace(withName: "F", stringValue: "http://example.com/fakenamespace") as! XMLNode]
XCTAssert(otherDoc.rootElement()?.namespaces?.count == 2)
XCTAssert(otherDoc.rootElement()?.namespaces?.flatMap({ $0.name })[0] == "R" && otherDoc.rootElement()?.namespaces?.flatMap({ $0.name })[1] == "F")
let namespaces: [XMLNode]? = otherDoc.rootElement()?.namespaces
let names: [String]? = namespaces?.flatMap { $0.name }
XCTAssertNotNil(names)
XCTAssert(names![0] == "R" && names![1] == "F")
otherDoc.rootElement()?.namespaces = nil
XCTAssert((otherDoc.rootElement()?.namespaces?.count ?? 0) == 0)
}
Expand Down
3 changes: 2 additions & 1 deletion TestFoundation/TestXMLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class TestXMLParser : XCTestCase {
return xmlUnderTest
}
if let open = encoding.range(of: "(") {
encoding = String(encoding[open.upperBound...])
let range: Range<String.Index> = open.upperBound..<encoding.endIndex
encoding = String(encoding[range])
}
if let close = encoding.range(of: ")") {
encoding = String(encoding[..<close.lowerBound])
Expand Down

0 comments on commit 9431ced

Please sign in to comment.