Преглед на файлове

Serializing tests running while still fast.

Tests are consciously run one at a time (not all at parallel and
relying on single-thread model to run only one at a time), while
pauses are still minimal because of more workers thrown
into setTimeout queue.

This is preparing for running async tests (which need to be
properly serialized).
Herbert Vojčík преди 11 години
родител
ревизия
1232d8861c
променени са 3 файла, в които са добавени 43 реда и са изтрити 16 реда
  1. 16 5
      js/SUnit.deploy.js
  2. 18 7
      js/SUnit.js
  3. 9 4
      st/SUnit.st

+ 16 - 5
js/SUnit.deploy.js

@@ -489,13 +489,24 @@ smalltalk.method({
 selector: "run",
 fn: function (){
 var self=this;
+var $1;
+var worker;
+var index;
 smalltalk.send(self["@result"],"_total_",[smalltalk.send(self["@suite"],"_size",[])]);
 smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
-smalltalk.send(self["@suite"],"_do_",[(function(each){
-return smalltalk.send((function(){
-smalltalk.send(each,"_runCaseFor_",[self["@result"]]);
-return smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
-}),"_valueWithTimeout_",[(100)]);
+index=(1);
+worker=(function(){
+$1=smalltalk.send(index,"__lt_eq",[smalltalk.send(self["@suite"],"_size",[])]);
+if(smalltalk.assert($1)){
+smalltalk.send(smalltalk.send(self["@suite"],"_at_",[index]),"_runCaseFor_",[self["@result"]]);
+index=smalltalk.send(index,"__plus",[(1)]);
+index;
+smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
+return smalltalk.send(worker,"_valueWithTimeout_",[(0)]);
+};
+});
+smalltalk.send(smalltalk.send(smalltalk.send(self["@suite"],"_size",[]),"_min_",[(25)]),"_timesRepeat_",[(function(){
+return smalltalk.send(worker,"_valueWithTimeout_",[(0)]);
 })]);
 return self}
 }),

+ 18 - 7
js/SUnit.js

@@ -675,18 +675,29 @@ selector: "run",
 category: 'actions',
 fn: function (){
 var self=this;
+var $1;
+var worker;
+var index;
 smalltalk.send(self["@result"],"_total_",[smalltalk.send(self["@suite"],"_size",[])]);
 smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
-smalltalk.send(self["@suite"],"_do_",[(function(each){
-return smalltalk.send((function(){
-smalltalk.send(each,"_runCaseFor_",[self["@result"]]);
-return smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
-}),"_valueWithTimeout_",[(100)]);
+index=(1);
+worker=(function(){
+$1=smalltalk.send(index,"__lt_eq",[smalltalk.send(self["@suite"],"_size",[])]);
+if(smalltalk.assert($1)){
+smalltalk.send(smalltalk.send(self["@suite"],"_at_",[index]),"_runCaseFor_",[self["@result"]]);
+index=smalltalk.send(index,"__plus",[(1)]);
+index;
+smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
+return smalltalk.send(worker,"_valueWithTimeout_",[(0)]);
+};
+});
+smalltalk.send(smalltalk.send(smalltalk.send(self["@suite"],"_size",[]),"_min_",[(25)]),"_timesRepeat_",[(function(){
+return smalltalk.send(worker,"_valueWithTimeout_",[(0)]);
 })]);
 return self},
 args: [],
-source: "run\x0a\x09result total: suite size.\x0a    announcer announce: (ResultAnnouncement new result: result).\x0a\x09suite do: [:each | [\x0a      \x09each runCaseFor: result.\x0a\x09    announcer announce: (ResultAnnouncement new result: result)\x0a\x09] valueWithTimeout: 100]\x0a",
-messageSends: ["total:", "size", "announce:", "result:", "new", "do:", "valueWithTimeout:", "runCaseFor:"],
+source: "run\x0a\x09| worker index |\x0a\x09result total: suite size.\x0a    announcer announce: (ResultAnnouncement new result: result).\x0a    index := 1.\x0a    worker := [ index <= suite size ifTrue: [\x0a\x09\x09(suite at: index) runCaseFor: result.\x0a        index := index + 1.\x0a\x09\x09announcer announce: (ResultAnnouncement new result: result).\x0a        worker valueWithTimeout: 0\x0a\x09]].\x0a\x09(suite size min: 25) timesRepeat: [ worker valueWithTimeout: 0 ]",
+messageSends: ["total:", "size", "announce:", "result:", "new", "ifTrue:", "runCaseFor:", "at:", "+", "valueWithTimeout:", "<=", "timesRepeat:", "min:"],
 referencedClasses: ["ResultAnnouncement"]
 }),
 smalltalk.TestSuiteRunner);

+ 9 - 4
st/SUnit.st

@@ -215,12 +215,17 @@ suite: aCollection
 !TestSuiteRunner methodsFor: 'actions'!
 
 run
+	| worker index |
 	result total: suite size.
     announcer announce: (ResultAnnouncement new result: result).
-	suite do: [:each | [
-      	each runCaseFor: result.
-	    announcer announce: (ResultAnnouncement new result: result)
-	] valueWithTimeout: 100]
+    index := 1.
+    worker := [ index <= suite size ifTrue: [
+		(suite at: index) runCaseFor: result.
+        index := index + 1.
+		announcer announce: (ResultAnnouncement new result: result).
+        worker valueWithTimeout: 0
+	]].
+	(suite size min: 25) timesRepeat: [ worker valueWithTimeout: 0 ]
 ! !
 
 !TestSuiteRunner methodsFor: 'initialization'!