Skip to content

Commit

Permalink
Broken unit tests pass again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Jolley committed Dec 21, 2009
1 parent e978772 commit 77d6e1c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
Expand Up @@ -96,8 +96,9 @@ test("destroying a record should change all", function() {
checkPreconditions();
SC.RunLoop.begin();
foo.destroy();
expect(foo,1,0); // calling destroy() should specifically change status
SC.RunLoop.end();
expect(foo,1,1);
expect(foo,2,1);
});

test("refreshing a record should change status", function() {
Expand Down
52 changes: 33 additions & 19 deletions frameworks/foundation/tests/system/request.js
Expand Up @@ -166,7 +166,6 @@ test("Test timeouts", function() {
// Sanity check 1
try {
SC.Request.getUrl(url).set('timeout', 0).send();
badRequest.send();
}
catch (e) {
message = e;
Expand All @@ -177,33 +176,48 @@ test("Test timeouts", function() {
try {
SC.Request.getUrl(url).set('isAsynchronous', NO).set('timeout', 10).send();
}
catch (e) {
message = e;
catch (e2) {
message = e2;
}
ok(message && message.indexOf("Timeout values cannot be used with synchronous requests") !== -1, 'An error should be thrown when trying to use a timeout with a synchronous request');


// Make sure timeouts actually fire, and fire when expected.
var changedBefore = changedAfter = NO,
callbackValue = "initial";
timeoutRequest = SC.Request.getUrl("http://www.sproutcore.com");
timeoutRequest.set('timeout', 20);
timeoutRequest.set('didTimeout', function() { callbackValue = "after timeout"; });
timeoutRequest.set('didReceive', function() { callbackValue = "received data"; });
var changedBefore = NO,
changedAfter = NO,
timeoutRequest = SC.Request.getUrl("http://www.sproutcore.com"),
checkstop;

var now = Date.now();

// make the timeout as short as possible so that it will always happen
timeoutRequest.set('timeout', 10);
timeoutRequest.set('didTimeout', function() {
// at least timeout time must have elapsed
var elapsed = Date.now()-now;
ok(elapsed >= 10, 'timeout must not fire earlier than 10msec - actual %@'.fmt(elapsed));

// timeout did fire...just resume...
clearTimeout(checkstop);
window.start();
});

timeoutRequest.set('didReceive', function() {
ok(false, 'timeout did not fire before response was recieved. should have fired after 10msec. response time: %@msec'.fmt(Date.now() - now));
window.start(); // resume
});

SC.RunLoop.begin();
timeoutRequest.send();
SC.RunLoop.end();

stop() ; // stops the test runner
setTimeout(function() {
changedBefore = (callbackValue !== "initial");
}, 10);
setTimeout(function() {
changedAfter = (callbackValue === "after timeout");

ok(!changedBefore, 'The timeout callback should not have run before the timeout value was exceeded');
ok(changedAfter, 'The timeout callback should have run after the timeout value was exceeded');
window.start() ; // starts the test runner
}, 5000);

// in case nothing works
checkstop = setTimeout(function() {
ok(false, 'timeout did not fire at all');
window.start();
}, 500);

});

2 changes: 1 addition & 1 deletion frameworks/runtime/system/logger.js
Expand Up @@ -168,7 +168,7 @@ SC.Logger = SC.Object.create({
return false;
}

if (this.get('exists') && typeof(reporter.debug) === "function") {
if (this.get('exists') && (typeof reporter.debug === "function")) {
reporter.debug.apply(reporter, arguments);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion frameworks/runtime/tests/system/logger.js
Expand Up @@ -27,12 +27,13 @@ function testConsole() {
trace: function() { return true; },
warn: function() { return true; }
};
};
}

module("SC.Logger", {
setup: function() {
SC.Logger.set('reporter', testConsole());

SC.Logger.debugEnabled = true;
SC.Logger.format = true;
SC.Logger.fallBackOnLog = true;
SC.Logger.fallBackOnAlert = false;
Expand Down

0 comments on commit 77d6e1c

Please sign in to comment.