Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added heartbeat for tests. Other fixes.

  • Loading branch information...
commit 7b462dffae1a9dfa846089a04c2b198ad241b870 1 parent d6f1ff6
@snej snej authored
View
9 App/AppDelegate.m
@@ -12,11 +12,6 @@
NSString* const AppDelegateCouchRestartedNotification = @"AppDelegateCouchRestarted";
-/** This is the name of the database the app will use -- customize it as you like,
- but the name must contain only *lowercase* letters, digits, and "-". */
-#define kDatabaseName @"data"
-
-
@interface AppDelegate ()
@property (readwrite, retain, nonatomic) NSURL* serverURL; // settable internally
@end
@@ -62,8 +57,8 @@ - (BOOL)application:(UIApplication *)application
-(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL
{
- gCouchLogLevel = 1; // You can increase this to 2 (or even 3, which is overkill)
- gRESTLogLevel = kRESTLogRequestURLs; // You can increase this to kRESTLogRequestURLs or higher
+ //gCouchLogLevel = 1;
+ //gRESTLogLevel = kRESTLogRequestURLs;
if (!self.serverURL)
self.serverURL = serverURL;
View
13 App/BeeCouchTest.m
@@ -35,7 +35,16 @@ - (void)dealloc {
- (NSURL*) serverURL {
- return ((AppDelegate*)[[UIApplication sharedApplication] delegate]).serverURL;
+ NSURL* url;
+ do {
+ url = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).serverURL;
+ if (!url) {
+ NSLog(@"Waiting for server to start...");
+ [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
+ beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
+ }
+ } while (!url);
+ return url;
}
@@ -47,7 +56,7 @@ - (NSString*) databaseName {
- (CouchServer*) server {
if (!_server) {
_server = [[CouchServer alloc] initWithURL: self.serverURL];
- // Track active operations so we can wait for their completion in didEnterBackground, below
+ // Track active operations so we can wait for their completion in serverWillSuspend, below
_server.tracksActiveOperations = YES;
}
return _server;
View
4 App/BeeTest.h
@@ -52,4 +52,8 @@
- (void) logFormat: (NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
- (BOOL) addTimestamp: (NSString*)message;
+@property NSTimeInterval heartbeatInterval;
+
+- (void) heartbeat;
+
@end
View
25 App/BeeTest.m
@@ -17,6 +17,7 @@ @interface BeeTest ()
{
BOOL _running;
NSMutableArray* _messages;
+ NSTimer* _heartbeat;
}
@property (readwrite, retain) NSDate* startTime;
@property (readwrite, retain) NSDate* endTime;
@@ -218,6 +219,7 @@ - (void) setUp {
}
- (void) tearDown {
+ self.heartbeatInterval = 0.0;
NSNotificationCenter* nctr = [NSNotificationCenter defaultCenter];
[nctr removeObserver: self
name:UIApplicationDidEnterBackgroundNotification
@@ -240,4 +242,27 @@ - (void)applicationWillEnterForeground: (NSNotification*)notification
}
+- (NSTimeInterval) heartbeatInterval {
+ return _heartbeat ? [_heartbeat timeInterval] : 0.0;
+}
+
+- (void) setHeartbeatInterval: (NSTimeInterval)interval {
+ [_heartbeat invalidate];
+ [_heartbeat release];
+ if (interval > 0) {
+ _heartbeat = [[NSTimer scheduledTimerWithTimeInterval: interval
+ target: self
+ selector: @selector(heartbeat)
+ userInfo: NULL
+ repeats: YES] retain];
+ } else {
+ _heartbeat = nil;
+ }
+}
+
+
+- (void) heartbeat {
+}
+
+
@end
View
2  App/TestListController.m
@@ -155,7 +155,7 @@ - (BeeTest*) testForClass: (Class)testClass {
- (BeeTest*) makeTestForClass: (Class)testClass {
BeeTest* test = [self testForClass: testClass];
if (!test) {
- test = [[testClass alloc] init];
+ test = [[[testClass alloc] init] autorelease];
if (test) {
[_activeTestByClass setObject: test forKey: NSStringFromClass(testClass)];
[test addObserver: self forKeyPath: @"running" options: 0 context: NULL];
View
22 App/TestListController.xib
@@ -3,12 +3,12 @@
<data>
<int key="IBDocument.SystemTarget">1280</int>
<string key="IBDocument.SystemVersion">11C57</string>
- <string key="IBDocument.InterfaceBuilderVersion">1934</string>
+ <string key="IBDocument.InterfaceBuilderVersion">1938</string>
<string key="IBDocument.AppKitVersion">1138.21</string>
<string key="IBDocument.HIToolboxVersion">567.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="NS.object.0">931</string>
+ <string key="NS.object.0">933</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
@@ -35,7 +35,7 @@
<int key="NSvFlags">274</int>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSWindow"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
@@ -46,7 +46,6 @@
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIBouncesZoom">NO</bool>
- <int key="IBUISeparatorStyle">2</int>
<int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
<bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
<float key="IBUIRowHeight">44</float>
@@ -120,11 +119,22 @@
<nil key="sourceID"/>
<int key="maxID">7</int>
</object>
- <object class="IBClassDescriber" key="IBDocument.Classes"/>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">TestListController</string>
+ <string key="superclassName">UITableViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/TestListController.h</string>
+ </object>
+ </object>
+ </array>
+ </object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
- <string key="IBCocoaTouchPluginVersion">931</string>
+ <string key="IBCocoaTouchPluginVersion">933</string>
</data>
</archive>
View
17 Tests/CountTest.m
@@ -12,17 +12,11 @@ @implementation CountTest
@synthesize count = _count, limit = _limit;
-- (void) logSoon {
- [self performSelector: @selector(logSomething) withObject: nil afterDelay: 1.0];
-}
-
-- (void) logSomething {
+- (void) heartbeat {
[self logFormat: @"Hi there! %i", ++_count, 45];
if (_count % 5 == 0)
self.status = [NSString stringWithFormat: @"Reached %i", _count];
- if (_limit == 0 || _count < _limit)
- [self logSoon];
- else {
+ if (_limit > 0 && _count >= _limit) {
self.errorMessage = @"O noes, count overflowed!!!";
self.running = NO;
}
@@ -31,12 +25,7 @@ - (void) logSomething {
- (void) setUp {
[super setUp];
_count = 0;
- [self logSoon];
-}
-
-- (void) tearDown {
- [NSObject cancelPreviousPerformRequestsWithTarget: self];
- [super tearDown];
+ self.heartbeatInterval = 1.0;
}
@end
View
4 Tests/CircleOfLifeTest.h → Tests/CreateDocsTest.h
@@ -1,5 +1,5 @@
//
-// CircleOfLifeTest.h
+// CreateDocsTest.h
// Worker Bee
//
// Created by Jens Alfke on 10/5/11.
@@ -8,6 +8,6 @@
#import "BeeCouchTest.h"
-@interface CircleOfLifeTest : BeeCouchTest
+@interface CreateDocsTest : BeeCouchTest
@end
View
39 Tests/CircleOfLifeTest.m → Tests/CreateDocsTest.m
@@ -1,54 +1,49 @@
//
-// CircleOfLifeTest.m
+// CreateDocsTest.m
// Worker Bee
//
// Created by Jens Alfke on 10/5/11.
// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
//
-#import "CircleOfLifeTest.h"
+#import "CreateDocsTest.h"
-@implementation CircleOfLifeTest
+#define kDocumentBatchSize 100
+
+
+@implementation CreateDocsTest
{
int _sequence;
}
+- (void) heartbeat {
+ if (self.suspended)
+ return;
-- (void) doSomethingSoon {
- if (self.running)
- [self performSelector: @selector(doSomething) withObject: nil afterDelay: 1.0];
-}
-
-- (void) doSomething {
- if (!self.suspended) {
+ [self logFormat: @"Adding docs %i--%i ...",
+ _sequence+1, _sequence+kDocumentBatchSize];
+ for (int i = 0; i < kDocumentBatchSize; i++) {
++_sequence;
NSString* dateStr = [RESTBody JSONObjectWithDate: [NSDate date]];
NSDictionary* props = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: _sequence], @"sequence",
dateStr, @"date", nil];
- [self logFormat: @"Adding doc: %@", props];
CouchDocument* doc = [self.database untitledDocument];
RESTOperation* op = [doc putProperties: props];
[op onCompletion: ^{
- if (op.error)
+ if (op.error) {
+ [self logFormat: @"!!! Failed to create doc %@", props];
self.error = op.error;
- else
- [self logFormat: @"..._id = %@", doc.documentID];
+ }
}];
}
- [self doSomethingSoon];
+ self.status = [NSString stringWithFormat: @"Created %i docs", _sequence];
}
- (void) setUp {
[super setUp];
_sequence = 0;
- [self doSomething];
+ self.heartbeatInterval = 1.0;
}
-- (void) tearDown {
- [NSObject cancelPreviousPerformRequestsWithTarget: self];
- [super tearDown];
-}
-
-
@end
View
13 Tests/NullTest.h
@@ -1,13 +0,0 @@
-//
-// NullTest.h
-// Worker Bee
-//
-// Created by Jens Alfke on 10/4/11.
-// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
-//
-
-#import "BeeTest.h"
-
-@interface NullTest : BeeTest
-
-@end
View
33 Tests/NullTest.m
@@ -1,33 +0,0 @@
-//
-// NullTest.m
-// Worker Bee
-//
-// Created by Jens Alfke on 10/4/11.
-// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
-//
-
-#import "NullTest.h"
-
-@implementation NullTest
-{
- int _count;
-}
-
-- (void) logSoon {
- [self performSelector: @selector(logSomething) withObject: nil afterDelay: 1.0];
-}
-
-- (void) logSomething {
- [self logFormat: @"Hi there! %i", ++_count, 45];
- [self logSoon];
-}
-
-- (void) setRunning:(BOOL)running {
- [super setRunning: running];
- if (running)
- [self logSoon];
- else
- [NSObject cancelPreviousPerformRequestsWithTarget: self];
-}
-
-@end
View
12 Worker Bee.xcodeproj/project.pbxproj
@@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */
27A07488143CCDCD0043BEB6 /* BeeCouchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A07487143CCDCD0043BEB6 /* BeeCouchTest.m */; };
- 27A0748C143CDE6B0043BEB6 /* CircleOfLifeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A0748B143CDE6B0043BEB6 /* CircleOfLifeTest.m */; };
+ 27A0748C143CDE6B0043BEB6 /* CreateDocsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A0748B143CDE6B0043BEB6 /* CreateDocsTest.m */; };
27B28FA614314FB800B86F18 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27B28FA514314FB800B86F18 /* UIKit.framework */; };
27B28FA814314FB800B86F18 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27B28FA714314FB800B86F18 /* Foundation.framework */; };
27B28FAA14314FB800B86F18 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27B28FA914314FB800B86F18 /* CoreGraphics.framework */; };
@@ -35,8 +35,8 @@
/* Begin PBXFileReference section */
27A07486143CCDCD0043BEB6 /* BeeCouchTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BeeCouchTest.h; sourceTree = "<group>"; };
27A07487143CCDCD0043BEB6 /* BeeCouchTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BeeCouchTest.m; sourceTree = "<group>"; };
- 27A0748A143CDE6B0043BEB6 /* CircleOfLifeTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CircleOfLifeTest.h; sourceTree = "<group>"; };
- 27A0748B143CDE6B0043BEB6 /* CircleOfLifeTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CircleOfLifeTest.m; sourceTree = "<group>"; };
+ 27A0748A143CDE6B0043BEB6 /* CreateDocsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; path = CreateDocsTest.h; sourceTree = "<group>"; };
+ 27A0748B143CDE6B0043BEB6 /* CreateDocsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CreateDocsTest.m; sourceTree = "<group>"; };
27B28FA114314FB800B86F18 /* Worker Bee.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Worker Bee.app"; sourceTree = BUILT_PRODUCTS_DIR; };
27B28FA514314FB800B86F18 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
27B28FA714314FB800B86F18 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -164,8 +164,8 @@
children = (
27CB656B143B9EB800EEA1F2 /* CountTest.h */,
27CB656C143B9EB800EEA1F2 /* CountTest.m */,
- 27A0748A143CDE6B0043BEB6 /* CircleOfLifeTest.h */,
- 27A0748B143CDE6B0043BEB6 /* CircleOfLifeTest.m */,
+ 27A0748A143CDE6B0043BEB6 /* CreateDocsTest.h */,
+ 27A0748B143CDE6B0043BEB6 /* CreateDocsTest.m */,
);
path = Tests;
sourceTree = "<group>";
@@ -245,7 +245,7 @@
27CB656D143B9EB900EEA1F2 /* CountTest.m in Sources */,
27CB6576143BAA2F00EEA1F2 /* BeeTestController.m in Sources */,
27A07488143CCDCD0043BEB6 /* BeeCouchTest.m in Sources */,
- 27A0748C143CDE6B0043BEB6 /* CircleOfLifeTest.m in Sources */,
+ 27A0748C143CDE6B0043BEB6 /* CreateDocsTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Please sign in to comment.
Something went wrong with that request. Please try again.