Skip to content

Commit dd34ea2

Browse files
ChrisJeffersonfingolfin
authored andcommitted
Add tests for slow IO
1 parent e97e61e commit dd34ea2

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ addons:
1717
- libreadline-dev
1818
- python
1919
- python-pip
20+
- perl
2021

2122
#
2223
# The following test jobs are roughly sorted by duration, from longest to
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env sh
2+
3+
# We use printf here to allow the arguments to contain '\n'
4+
# so we can explictly control where newlines appear.
5+
printf "$2"
6+
sleep 1
7+
printf "$3"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#@local scriptdir, write, checkPartialRead, process, c
2+
#
3+
gap> START_TEST("streamio.tst");
4+
gap> scriptdir := DirectoriesLibrary( "tst/teststandard/processes/" );;
5+
gap> write := Filename(scriptdir, "slowwrite.sh");;
6+
7+
# Read the output of 'prog', using 'readfunc'. The output should
8+
# come in two parts, 'firstread' and 'secondread'.
9+
# If GAP is too slow, allow 'firstread' and 'secondread' to be read
10+
# in one step, but then return 'false'.
11+
# We run this function multiple times to avoid very occasional failures
12+
# due to OS scheduling.
13+
gap> checkPartialRead := function(prog, readfunc, firstread, secondread)
14+
> local process, l;
15+
> process := InputOutputLocalProcess(DirectoryCurrent(), prog, ["prog", firstread, secondread]);
16+
> l := ReadLine(process);
17+
> if l = Concatenation(firstread, secondread) then
18+
> if ReadLine(process) <> fail then Error("Invalid end - type 1"); fi;
19+
> CloseStream(process);
20+
> return false;
21+
> else
22+
> if ReadLine(process) <> secondread then Error("Missing second"); fi;
23+
> if ReadLine(process) <> fail then Error("Invalid end - type 2"); fi;
24+
> CloseStream(process);
25+
> return true;
26+
> fi;
27+
> end;;
28+
gap> ForAny([1..10], x -> checkPartialRead(write, ReadLine, "aaa", "aaa\n"));
29+
true
30+
gap> ForAny([1..10], x -> checkPartialRead(write, ReadLine, "aaa", "aaa"));
31+
true
32+
gap> ForAny([1..10], x -> checkPartialRead(write, ReadAll, "aaa", "aaa\n"));
33+
true
34+
35+
# Read as bytes, which is always identical
36+
gap> process := InputOutputLocalProcess(DirectoryCurrent(), write, ["prog", "abc", "def"]);
37+
< input/output stream to slowwrite.sh >
38+
gap> c := ReadByte(process);
39+
97
40+
gap> c := ReadByte(process);
41+
98
42+
gap> c := ReadByte(process);
43+
99
44+
gap> c := ReadByte(process);
45+
100
46+
gap> c := ReadByte(process);
47+
101
48+
gap> c := ReadByte(process);
49+
102
50+
gap> c := ReadByte(process);
51+
fail
52+
gap> CloseStream(process);
53+
gap> STOP_TEST("streamio.tst", 1);

0 commit comments

Comments
 (0)