#QUALITY by cg
authorClaus Gittinger <cg@exept.de>
Mon, 19 Mar 2018 14:50:42 +0100
changeset 1903 dcd4e2bf4c31
parent 1902 dba6552c3871
child 1904 a87e221839de
#QUALITY by cg class: RegressionTests::PipeStreamTest comment/format in: #testReadCheckPipe5 changed: #testReadCheckPipe4 #testReadPipe6 #testReadPipe7
RegressionTests__PipeStreamTest.st
--- a/RegressionTests__PipeStreamTest.st	Mon Mar 19 14:49:42 2018 +0100
+++ b/RegressionTests__PipeStreamTest.st	Mon Mar 19 14:50:42 2018 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'stx:goodies/regression' }"
 
 "{ NameSpace: RegressionTests }"
@@ -70,28 +72,27 @@
     "readCheck a pipe.
      Do this and interrupt the reading thread heavily"
 
-    | s p count nLoop|
-
-    nLoop := 1000.
+    | s p count|
 
-    "/ self createTestFile.
-
-    s := PipeStream readingFrom:'sleep 5'.
+    s := PipeStream readingFrom:'sleep 3'.
 
     p := [
-	s readWait.
-	'readWait finished' printCR.
+        s readWait.
+        '   --- testReadCheckPipe4: readWait finished' printCR.
     ] forkAt:7.
 
     count := 0.
     [p isDead] whileFalse:[
-	Delay waitForMilliseconds:5.
-	p interruptWith:[count := count + 1].
+        Delay waitForMilliseconds:5.
+        p interruptWith:[count := count + 1].
     ].
-    ('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
+    ('   --- testReadCheckPipe4: readWait interrupted <1p> times' expandMacrosWith:count) printCR.
 
     s close.
 
+    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
+    self assert:(count >= (3 / (1/20))).
+
     "
      self new testReadCheckPipe4
     "
@@ -103,28 +104,29 @@
     "readCheck a pipe.
      Do this and interrupt the reading thread heavily"
 
-    | s p count nLoop|
-
-    nLoop := 1000.
+    | s p count line|
 
-    "/ self createTestFile.
-
-    s := PipeStream readingFrom:'sleep 5; echo hello'.
+    s := PipeStream readingFrom:'sleep 3; echo hello'.
 
     p := [
-	s readWait.
-	'readWait finished' printCR.
+        s readWait.
+        line := s nextLine.
+        '   --- testReadCheckPipe5: readWait finished' printCR.
     ] forkAt:7.
 
     count := 0.
     [p isDead] whileFalse:[
-	Delay waitForMilliseconds:5.
-	p interruptWith:[count := count + 1].
+        Delay waitForMilliseconds:5.
+        p interruptWith:[count := count + 1].
     ].
-    ('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
+    ('   --- testReadCheckPipe5: readWait interrupted <1p> times' expandMacrosWith:count) printCR.
 
     s close.
 
+    self assert:(line = 'hello').
+    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
+    self assert:(count >= (3 / (1/20))).
+
     "
      self new testReadCheckPipe5
     "
@@ -136,33 +138,35 @@
     "read a pipe.
      Do this and interrupt the reading thread heavily"
 
-    | s p count nLoop error |
+    | s p count error line |
 
     error := nil.
-    nLoop := 1000.
 
     "/ self createTestFile.
 
-    s := PipeStream readingFrom:'sleep 5'.
+    s := PipeStream readingFrom:'sleep 3'.
 
     p := [
-	[
-	    'read: ' print. s nextLine printCR.
-	] on: Error do:[:ex|
-	    error := ex.
-	]
+        [
+            line := s nextLine printCR.
+        ] on: Error do:[:ex|
+            error := ex.
+        ]
     ] forkAt:7.
 
     count := 0.
     [p isDead] whileFalse:[
-	Delay waitForMilliseconds:5.
-	p interruptWith:[count := count + 1].
+        Delay waitForMilliseconds:5.
+        p interruptWith:[count := count + 1].
     ].
-    ('read interrupted <1p> times' expandMacrosWith:count) printCR.
+    ('   --- testReadPipe6: read interrupted <1p> times' expandMacrosWith:count) printCR.
 
     s close.
 
-    self assert: error isNil
+    self assert: error isNil.
+    self assert: line isEmptyOrNil.
+    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
+    self assert:(count >= (3 / (1/20))).
 
     "
      self new testReadPipe6
@@ -175,32 +179,31 @@
     "read a pipe.
      Do this and interrupt the reading thread heavily"
 
-    |s p count nLoop error |
-
-    nLoop := 1000.
+    |s p count error line |
 
-    "/ self createTestFile.
-
-    s := PipeStream readingFrom:'sleep 5; echo hello'.
+    s := PipeStream readingFrom:'sleep 3; echo hello'.
 
     p := [
-	[
-	    'read: ' print. s nextLine printCR.
-	] on: Error do:[:ex|
-	    error := ex.
-	]
+        [
+            line := s nextLine printCR.
+        ] on: Error do:[:ex|
+            error := ex.
+        ]
     ] forkAt:7.
 
     count := 0.
     [p isDead] whileFalse:[
-	Delay waitForMilliseconds:5.
-	p interruptWith:[count := count + 1].
+        Delay waitForMilliseconds:5.
+        p interruptWith:[count := count + 1].
     ].
     ('read interrupted <1p> times' expandMacrosWith:count) printCR.
 
     s close.
 
-    self assert: error isNil
+    self assert: error isNil.
+    self assert: line = 'hello'.
+    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
+    self assert:(count >= (3 / (1/20))).
 
     "
      self test7