Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0bea15f

Browse files
committedMay 24, 2015
[Test] Reproduce then() task-flow bug when chaining with different Error types.
1 parent 262681e commit 0bea15f

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
 

‎SwiftTask.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
1F20250219ADA8FD00DE0495 /* BasicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F20250119ADA8FD00DE0495 /* BasicTests.swift */; };
1111
1F218D5B1AFC3FFD00C849FF /* RemoveHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F218D5A1AFC3FFD00C849FF /* RemoveHandlerTests.swift */; };
1212
1F218D5C1AFC3FFD00C849FF /* RemoveHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F218D5A1AFC3FFD00C849FF /* RemoveHandlerTests.swift */; };
13+
1F29F6421B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F29F6411B115EF500F476AF /* MultipleErrorTypesTests.swift */; };
14+
1F29F6431B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F29F6411B115EF500F476AF /* MultipleErrorTypesTests.swift */; };
1315
1F46DEDA199EDF1000F97868 /* SwiftTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F46DED9199EDF1000F97868 /* SwiftTask.h */; settings = {ATTRIBUTES = (Public, ); }; };
1416
1F46DEFB199EDF8100F97868 /* SwiftTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEFA199EDF8100F97868 /* SwiftTask.swift */; };
1517
1F46DEFD199EE2C200F97868 /* _TestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEFC199EE2C200F97868 /* _TestCase.swift */; };
@@ -46,6 +48,7 @@
4648
/* Begin PBXFileReference section */
4749
1F20250119ADA8FD00DE0495 /* BasicTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicTests.swift; sourceTree = "<group>"; };
4850
1F218D5A1AFC3FFD00C849FF /* RemoveHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoveHandlerTests.swift; sourceTree = "<group>"; };
51+
1F29F6411B115EF500F476AF /* MultipleErrorTypesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipleErrorTypesTests.swift; sourceTree = "<group>"; };
4952
1F46DED4199EDF1000F97868 /* SwiftTask.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftTask.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5053
1F46DED8199EDF1000F97868 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5154
1F46DED9199EDF1000F97868 /* SwiftTask.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftTask.h; sourceTree = "<group>"; };
@@ -161,6 +164,7 @@
161164
485C31F01A1D619A00040DA3 /* TypeInferenceTests.swift */,
162165
1F218D5A1AFC3FFD00C849FF /* RemoveHandlerTests.swift */,
163166
1F5FA35619A374E600975FB9 /* AlamofireTests.swift */,
167+
1F29F6411B115EF500F476AF /* MultipleErrorTypesTests.swift */,
164168
1F46DEE1199EDF1000F97868 /* Supporting Files */,
165169
);
166170
path = SwiftTaskTests;
@@ -366,6 +370,7 @@
366370
1FF52EB41A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */,
367371
1F218D5B1AFC3FFD00C849FF /* RemoveHandlerTests.swift in Sources */,
368372
1F6A8CA319A4E4F200369A5D /* SwiftTaskTests.swift in Sources */,
373+
1F29F6421B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */,
369374
1F4C76A41AD8CF40004E47C1 /* AlamofireTests.swift in Sources */,
370375
485C31F11A1D619A00040DA3 /* TypeInferenceTests.swift in Sources */,
371376
48511C5B19C17563002FE03C /* RetainCycleTests.swift in Sources */,
@@ -381,6 +386,7 @@
381386
4822F0DD19D00B2300F5F572 /* BasicTests.swift in Sources */,
382387
1F218D5C1AFC3FFD00C849FF /* RemoveHandlerTests.swift in Sources */,
383388
1FF52EB51A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */,
389+
1F29F6431B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */,
384390
1F4C76A51AD8CF41004E47C1 /* AlamofireTests.swift in Sources */,
385391
485C31F21A1D619A00040DA3 /* TypeInferenceTests.swift in Sources */,
386392
4822F0DC19D00B2300F5F572 /* _TestCase.swift in Sources */,
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// MultipleErrorTypesTests.swift
3+
// SwiftTask
4+
//
5+
// Created by Yasuhiro Inami on 2015/05/24.
6+
// Copyright (c) 2015年 Yasuhiro Inami. All rights reserved.
7+
//
8+
9+
import SwiftTask
10+
import Async
11+
import XCTest
12+
13+
class MultipleErrorTypesTests: _TestCase
14+
{
15+
enum MyEnum
16+
{
17+
case Default
18+
}
19+
20+
struct Dummy {}
21+
22+
typealias Task1 = Task<String, String, String>
23+
typealias Task2 = Task<MyEnum, MyEnum, MyEnum>
24+
25+
var flow = [Int]()
26+
27+
// delayed task + counting flow 1 & 2
28+
func _task1(#success: Bool) -> Task1
29+
{
30+
return Task1 { progress, fulfill, reject, configure in
31+
println("[task1] start")
32+
self.flow += [1]
33+
34+
Async.main(after: 0.1) {
35+
println("[task1] end")
36+
self.flow += [2]
37+
38+
success ? fulfill("OK") : reject("NG")
39+
}
40+
return
41+
}
42+
}
43+
44+
// delayed task + counting flow 4 & 5
45+
func _task2(#success: Bool) -> Task2
46+
{
47+
return Task2 { progress, fulfill, reject, configure in
48+
println("[task2] start")
49+
self.flow += [4]
50+
51+
Async.main(after: 0.1) {
52+
println("[task2] end")
53+
self.flow += [5]
54+
55+
success ? fulfill(.Default) : reject(.Default)
56+
}
57+
return
58+
}
59+
}
60+
61+
func testMultipleErrorTypes_then()
62+
{
63+
var expect = self.expectationWithDescription(__FUNCTION__)
64+
65+
self._task1(success: true)
66+
.then { value, errorInfo -> Task2 in
67+
68+
println("task1.then")
69+
self.flow += [3]
70+
71+
return self._task2(success: true)
72+
73+
}
74+
.then { value, errorInfo -> Void in
75+
76+
println("task1.then.then (task2 should end at this point)")
77+
self.flow += [6]
78+
79+
XCTAssertEqual(self.flow, Array(1...6), "Tasks should flow in order from 1 to 6.")
80+
expect.fulfill()
81+
82+
}
83+
84+
self.wait()
85+
}
86+
}

0 commit comments

Comments
 (0)
Please sign in to comment.