Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMPhobos
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMPhobos
Commits
9adf3bfc
Commit
9adf3bfc
authored
Sep 17, 2019
by
井庆林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改因为异步处理数据导致的单元测试无法走通
parent
1e21ef15
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+30
-0
Phobos.m
GMPhobos/Classes/Phobos.m
+2
-2
No files found.
Example/Tests/GMPhotoTest.m
View file @
9adf3bfc
...
...
@@ -20,6 +20,7 @@ NSString *const MockCityId = @"beijing";
@interface
GMPhotoTest
:
XCTestCase
@end
///[NSThread sleepForTimeInterval:0.2]; 因为是异步处理数据,所以需要延迟获取,进行单元测试
@implementation
GMPhotoTest
-
(
void
)
setUp
{
...
...
@@ -44,9 +45,11 @@ NSString *const MockCityId = @"beijing";
* @since <#version number#>
*/
-
(
void
)
testClientWithUserId
{
[
Phobos
removeAllNormalPhobosData
];
[
Phobos
.
sharedClient
setUserId
:
MockUserId
];
[
Phobos
.
sharedClient
setCurrentCityId
:
MockCityId
];
[
Phobos
track
:
MockEventId
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
...
...
@@ -61,6 +64,7 @@ NSString *const MockCityId = @"beijing";
*/
-
(
void
)
testTrackEventWithoutAttr
{
[
Phobos
track
:
MockEventId
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
...
...
@@ -76,6 +80,7 @@ NSString *const MockCityId = @"beijing";
-
(
void
)
testTrackEventWithAttr
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
...
...
@@ -152,8 +157,10 @@ NSString *const MockCityId = @"beijing";
[
Phobos
removeAllNormalPhobosData
];
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
//
[
NSThread
sleepForTimeInterval
:
0
.
2
];
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
...
...
@@ -161,9 +168,12 @@ NSString *const MockCityId = @"beijing";
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
[
NSThread
sleepForTimeInterval
:
0
.
2
];
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
}
...
...
@@ -180,23 +190,28 @@ NSString *const MockCityId = @"beijing";
for
(
int
i
=
0
;
i
<
30
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
31
,
@"array shouldn't be empty"
);
}
...
...
@@ -211,23 +226,28 @@ NSString *const MockCityId = @"beijing";
NSDictionary
*
sendNowAttr
=
@{
@"attr"
:
@"track_attr_send_now"
};
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
3
,
@"array shouldn't be empty"
);
}
...
...
@@ -242,15 +262,18 @@ NSString *const MockCityId = @"beijing";
//
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
}
...
...
@@ -294,6 +317,7 @@ NSString *const MockCityId = @"beijing";
[
controller
viewWillAppear
:
true
];
[
controller
viewWillDisappear
:
true
];
[
self
paramUnNilCheck
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
...
...
@@ -303,11 +327,13 @@ NSString *const MockCityId = @"beijing";
}
-
(
void
)
testSimulativePageViewEvent
{
[
NSThread
sleepForTimeInterval
:
0
.
2
];
[
Phobos
.
sharedClient
simulativePV
:
nil
businessId
:
nil
referer
:
nil
];
[
self
paramUnNilCheck
];
}
-
(
void
)
paramUnNilCheck
{
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
...
...
@@ -345,6 +371,7 @@ NSString *const MockCityId = @"beijing";
[
dict
setObject
:
@
(
0
)
forKey
:
@"is_push"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
array
.
count
==
1
,
@"PhobosCacheKey 下面应该有数据"
);
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
...
...
@@ -356,10 +383,13 @@ NSString *const MockCityId = @"beijing";
[
NSThread
sleepForTimeInterval
:
1
];
//模拟浏览页面,让out和in时间相差1s
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
2
,
@"PhobosCacheKey 上条数据应该发送"
);
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
2
,
@"PhobosCacheKey 上条数据不应该发送"
);
[
Phobos
track
:
@"test"
attributes
:
dict
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
3
,
@"PhobosCacheKey 上条数据应该发送"
);
}
...
...
GMPhobos/Classes/Phobos.m
View file @
9adf3bfc
...
...
@@ -442,7 +442,7 @@ static dispatch_queue_t _normalQueue;
}
+
(
void
)
track
:
(
NSString
*
)
eventName
{
[
self
track
:
eventName
attributes
:
nil
sendNow
:
NO
currentAPI
:
_sharedClient
.
serverAPI
];
[
self
track
:
eventName
attributes
:
@{}
sendNow
:
NO
currentAPI
:
_sharedClient
.
serverAPI
];
}
+
(
void
)
track
:
(
NSString
*
)
eventName
attributes
:
(
NSDictionary
*
)
attributes
{
...
...
@@ -454,7 +454,7 @@ static dispatch_queue_t _normalQueue;
}
+
(
void
)
track
:
(
NSString
*
)
eventName
currentAPI
:
(
NSString
*
)
currentAPI
{
[
self
track
:
eventName
attributes
:
nil
sendNow
:
NO
currentAPI
:
currentAPI
];
[
self
track
:
eventName
attributes
:
@{}
sendNow
:
NO
currentAPI
:
currentAPI
];
}
+
(
void
)
track
:
(
NSString
*
)
eventName
attributes
:
(
NSDictionary
*
)
attributes
currentAPI
:
(
NSString
*
)
currentAPI
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment