Skip to content

Commit

Permalink
[FIX] Failing unit tests closes #90
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Krey committed Jan 13, 2016
1 parent 68f4f51 commit 9db29b5
Show file tree
Hide file tree
Showing 67 changed files with 608 additions and 77 deletions.
6 changes: 0 additions & 6 deletions MQTTClient/MQTTClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@
84998C8D1C0EE26600119061 /* MQTTSessionSynchron.h in Headers */ = {isa = PBXBuildFile; fileRef = 84998C871C0EDBAA00119061 /* MQTTSessionSynchron.h */; settings = {ATTRIBUTES = (Public, ); }; };
84998C941C0EE3D600119061 /* MQTTSessionSynchron.m in Sources */ = {isa = PBXBuildFile; fileRef = 84998C881C0EDBAA00119061 /* MQTTSessionSynchron.m */; };
84998C951C0EE3D600119061 /* MQTTSessionLegacy.m in Sources */ = {isa = PBXBuildFile; fileRef = 84998C811C0ED09700119061 /* MQTTSessionLegacy.m */; };
84A592141C3C5343008C5199 /* MQTTTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 84A592131C3C5343008C5199 /* MQTTTransport.m */; };
84A592151C3C5343008C5199 /* MQTTTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 84A592131C3C5343008C5199 /* MQTTTransport.m */; };
84A592161C3C5343008C5199 /* MQTTTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 84A592131C3C5343008C5199 /* MQTTTransport.m */; };
84A592171C3C5343008C5199 /* MQTTTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 84A592131C3C5343008C5199 /* MQTTTransport.m */; };
84A592181C3C64A9008C5199 /* MQTTSSLSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 841D0A7A1C35876E006A82DC /* MQTTSSLSecurityPolicy.m */; };
84A592191C3C64A9008C5199 /* MQTTSSLSecurityPolicyDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 841D0A7C1C35876E006A82DC /* MQTTSSLSecurityPolicyDecoder.m */; };
Expand Down Expand Up @@ -1165,7 +1162,6 @@
84B6A1A11C15E51300618573 /* MQTTTestWebsockets.m in Sources */,
84C845A61BDD8DE300FEC354 /* MQTTTestFlows.m in Sources */,
8435A25F1BF3C69200D2BF33 /* MQTTTestBlocks.m in Sources */,
84A592161C3C5343008C5199 /* MQTTTransport.m in Sources */,
840716511BBEF19E00FBB3CB /* MQTTSSLSecurityPolicyTests.m in Sources */,
840716531BBEF19E00FBB3CB /* MQTTClientTests.m in Sources */,
840716541BBEF19E00FBB3CB /* MQTTTestMultiThreading.m in Sources */,
Expand All @@ -1185,7 +1181,6 @@
files = (
84C845A51BDD8DD900FEC354 /* MQTTTestFlows.m in Sources */,
8435A25E1BF3C69200D2BF33 /* MQTTTestBlocks.m in Sources */,
84A592151C3C5343008C5199 /* MQTTTransport.m in Sources */,
8425D70E1BBE8D68005AD733 /* MQTTClientSubscriptionTests.m in Sources */,
8407160E1BBEE6A000FBB3CB /* SwiftTests.swift in Sources */,
8407160B1BBEE68900FBB3CB /* MQTTTestSessionManager.m in Sources */,
Expand All @@ -1206,7 +1201,6 @@
8429773F1B87CEF600A119FB /* MQTTTestSessionManager.m in Sources */,
8435A25D1BF3C69200D2BF33 /* MQTTTestBlocks.m in Sources */,
C21D3C711B1EBD730012DD2F /* MQTTSSLSecurityPolicyTests.m in Sources */,
84A592141C3C5343008C5199 /* MQTTTransport.m in Sources */,
840785A918A2AA26009158D5 /* MQTTClientPublishTests.m in Sources */,
84B6A1891C133A9F00618573 /* MQTTTestWebsockets.m in Sources */,
8461914A1883E56800101409 /* MQTTClientTests.m in Sources */,
Expand Down
7 changes: 4 additions & 3 deletions MQTTClient/MQTTClient/MQTTCoreDataPersistence.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ - (MQTTFlow *)flowforClientId:(NSString *)clientId
messageId:(UInt16)messageId {
__block MQTTFlow *flow = nil;

DDLogVerbose(@"flowforClientId requestingPerform");
[self.managedObjectContext performBlockAndWait:^{

DDLogVerbose(@"flowforClientId performing");

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"MQTTFlow"];
fetchRequest.predicate = [NSPredicate predicateWithFormat:
@"clientId = %@ and incomingFlag = %@ and messageId = %@",
Expand All @@ -175,9 +177,8 @@ - (MQTTFlow *)flowforClientId:(NSString *)clientId
flow = [flows lastObject];
}
}

}];

DDLogVerbose(@"flowforClientId performed");
return flow;
}

Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/MQTTClient/MQTTDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ - (void)stream:(NSStream*)sender handleEvent:(NSStreamEvent)eventCode {
DDLogVerbose(@"[MQTTDecoder] received (%lu)=%@...", (unsigned long)self.dataBuffer.length,
[self.dataBuffer subdataWithRange:NSMakeRange(0, MIN(256, self.dataBuffer.length))]);
[self.delegate decoder:self didReceiveMessage:self.dataBuffer];
self.dataBuffer = NULL;
self.dataBuffer = nil;
self.state = MQTTDecoderStateDecodingHeader;
}
}
Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/MQTTClient/MQTTMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ - (NSData *)wireFormat {
while (length > 0);

// encode message data
if (self.data != NULL) {
if (self.data != nil) {
[buffer appendData:self.data];
}

Expand Down
3 changes: 3 additions & 0 deletions MQTTClient/MQTTClient/MQTTSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -936,13 +936,16 @@ - (void)error:(MQTTSessionEvent)eventCode error:(NSError *)error {
}

- (UInt16)nextMsgId {
DDLogVerbose(@"nextMsgId synchronizing");
@synchronized(self) {
DDLogVerbose(@"nextMsgId synchronized");
self.txMsgId++;
while (self.txMsgId == 0 || [self.persistence flowforClientId:self.clientId
incomingFlag:NO
messageId:self.txMsgId] != nil) {
self.txMsgId++;
}
DDLogVerbose(@"nextMsgId synchronized done");
return self.txMsgId;
}
}
Expand Down
3 changes: 2 additions & 1 deletion MQTTClient/MQTTClientTests/MQTTClientTests-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

#import <XCTest/XCTest.h>
#import "MQTTClient.h"
#import "MQTTTestHelpers.h"
#import "MQTTTestHelpers.h"
#import "MQTTSessionManager.h"
3 changes: 2 additions & 1 deletion MQTTClient/MQTTClientTests/MQTTTestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <XCTest/XCTest.h>

#import "MQTTClient.h"
#import "MQTTSessionManager.h"
#import "MQTTSSLSecurityPolicy.h"

#define LOG_LEVEL_DEF ddLogLevel
Expand All @@ -25,7 +26,7 @@ static const DDLogLevel ddLogLevel = DDLogLevelWarning;
#define BULK 100 // some test servers are limited in queue size
#define ALOT 1000 // some test servers are limited in queue size

@interface MQTTTestHelpers : XCTestCase <MQTTSessionDelegate>
@interface MQTTTestHelpers : XCTestCase <MQTTSessionDelegate, MQTTSessionManagerDelegate>
- (void)timedout:(id)object;

+ (MQTTSession *)session:(NSDictionary *)parameters;
Expand Down
8 changes: 8 additions & 0 deletions MQTTClient/MQTTClientTests/MQTTTestHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ - (void)newMessage:(MQTTSession *)session data:(NSData *)data onTopic:(NSString
}
}

- (void)handleMessage:(NSData *)data onTopic:(NSString *)topic retained:(BOOL)retained {
DDLogVerbose(@"[MQTTTestHelpers] handleMessage r%d %@:%@",
retained, topic, data);
if (topic && [topic hasPrefix:@"$"]) {
self.SYSreceived = true;
}
}

- (void)handleEvent:(MQTTSession *)session event:(MQTTSessionEvent)eventCode error:(NSError *)error {
DDLogVerbose(@"[MQTTTestHelpers] handleEvent:%ld error:%@", (long)eventCode, error);
self.event = eventCode;
Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/MQTTClientTests/MQTTTestHelpers.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<array>
<string>#local</string>
<string>mosquitto</string>
<string>mosquittoWS</string>
<string>#mosquittoWS</string>
<string>#mosquittoTLS</string>
<string>#mosquittoTLSClientCert</string>
<string>#mosquittoWSS</string>
Expand Down
33 changes: 33 additions & 0 deletions MQTTClient/MQTTClientTests/SwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ class SwiftTests : MQTTTestHelpers {
}
}

func testSessionManager() {
for brokerName in brokers.allKeys {
var broker: NSDictionary;
broker = brokers.valueForKey(brokerName as! String) as! NSDictionary;
if (broker.valueForKey("websocket"))?.boolValue != true {

let m = MQTTSessionManager()
m.delegate = self

m.connectTo(broker.valueForKey("host") as! String,
port: (broker.valueForKey("port")?.integerValue)!,
tls: (broker.valueForKey("tls")?.boolValue)!,
keepalive: 60,
clean: true,
auth: false,
user: nil,
pass: nil,
will: false,
willTopic: nil,
willMsg: nil,
willQos: MQTTQosLevel.AtMostOnce,
willRetainFlag: false,
withClientId: nil)

while (m.state != MQTTSessionManagerState.Connected) {
print("waiting for connect %d", m.state);
NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 1))
}

}
}
}

override func handleEvent(session: MQTTSession!, event eventCode: MQTTSessionEvent, error: NSError!) {
switch eventCode {
case .Connected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/dist/documentation/html/annotated.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:45 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
</table></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</table></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 5 2016 21:51:44 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
Generated on Wed Jan 13 2016 22:45:17 for MQTTClient by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
Expand Down
Loading

0 comments on commit 9db29b5

Please sign in to comment.