Skip to content

Commit 1a6c56d

Browse files
committed
code coverage & multiprocessing bug fix in unittest-parallel
1 parent 0891abe commit 1a6c56d

File tree

8 files changed

+75
-20
lines changed

8 files changed

+75
-20
lines changed

.github/workflows/javaTests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ on:
2929
- '*.html'
3030
- 'src/main/python/**'
3131
- 'dev/**'
32+
- '.github/workflows/python.yml'
3233
branches:
3334
- main
3435
pull_request:
@@ -38,6 +39,7 @@ on:
3839
- '*.html'
3940
- 'src/main/python/**'
4041
- 'dev/**'
42+
- '.github/workflows/python.yml'
4143
branches:
4244
- main
4345

.github/workflows/python.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,27 @@ jobs:
132132
export SYSDS_QUIET=1
133133
export LOG4JPROP=$SYSTEMDS_ROOT/src/test/resources/log4j.properties
134134
cd src/main/python
135+
136+
# parallel tests
135137
unittest-parallel -t . -s tests -v
138+
139+
# non parallel tests
140+
python -m unittest discover -s tests/non_parallel_tests
141+
136142
# python -m unittest discover -s tests -p 'test_*.py'
137143
echo "Exit Status: " $?
138144
139145
- name: Run all python tests no environment
140146
run: |
141147
export LOG4JPROP=$(pwd)/src/test/resources/log4j.properties
142148
cd src/main/python
149+
150+
# parallel tests
143151
unittest-parallel -t . -s tests -v
152+
153+
# non parallel tests
154+
python -m unittest discover -s tests/non_parallel_tests
155+
144156
# python -m unittest discover -s tests -p 'test_*.py'
145157
echo "Exit Status: " $?
146158

src/main/java/org/apache/sysds/api/PythonDMLScript.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,16 @@ public MatrixBlock startReadingMbFromPipe(int id, int rlen, int clen, Types.Valu
126126
double[] denseBlock = new double[(int) limit];
127127
UnixPipeUtils.readNumpyArrayInBatches(pipe, id, BATCH_SIZE, (int) limit, type, denseBlock, 0);
128128
mb.init(denseBlock, rlen, clen);
129+
} else {
130+
throw new DMLRuntimeException("FIFO Pipes are not initialized.");
129131
}
130132
mb.recomputeNonZeros();
131133
mb.examSparsity();
132134
LOG.debug("Reading from Python finished");
133135
return mb;
134136
}
135137

136-
public MatrixBlock startReadingMbFromPipes(int[] blockSizes, int rlen, int clen, Types.ValueType type) throws IOException {
138+
public MatrixBlock startReadingMbFromPipes(int[] blockSizes, int rlen, int clen, Types.ValueType type) throws ExecutionException, InterruptedException {
137139
long limit = (long) rlen * clen;
138140
if(limit > Integer.MAX_VALUE)
139141
throw new DMLRuntimeException("Dense NumPy array of size " + limit +
@@ -157,21 +159,12 @@ public MatrixBlock startReadingMbFromPipes(int[] blockSizes, int rlen, int clen,
157159
}
158160
// Wait for all tasks and propagate exceptions
159161
for (Future<Void> f : futures) {
160-
try {
161-
f.get();
162-
} catch (ExecutionException e) {
163-
Throwable cause = e.getCause();
164-
if (cause instanceof IOException)
165-
throw (IOException) cause;
166-
else
167-
throw new RuntimeException("Pipe reader thread failed", cause);
168-
} catch (InterruptedException e) {
169-
Thread.currentThread().interrupt();
170-
throw new RuntimeException("Pipe reader interrupted", e);
171-
}
162+
f.get();
172163
}
173164

174165
mb.init(denseBlock, rlen, clen);
166+
} else {
167+
throw new DMLRuntimeException("FIFO Pipes are not initialized.");
175168
}
176169
mb.recomputeNonZeros();
177170
mb.examSparsity();
@@ -186,6 +179,8 @@ public void startWritingMbToPipe(int id, MatrixBlock mb) throws IOException {
186179

187180
BufferedOutputStream out = toPython.get(id);
188181
UnixPipeUtils.writeNumpyArrayInBatches(out, id, BATCH_SIZE, numElem, Types.ValueType.FP64, mb);
182+
} else {
183+
throw new DMLRuntimeException("FIFO Pipes are not initialized.");
189184
}
190185
}
191186

src/main/java/org/apache/sysds/runtime/util/UnixPipeUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ public static void writeNumpyArrayInBatches(BufferedOutputStream out, int id, in
204204

205205
// Fill buffer from MatrixBlock into byte[] (typed)
206206
int bytesWritten = fillByteArrayFromDoubleArray(type, mb, offset, buffer, currentBatchSize);
207-
if (bytesWritten != currentBatchSize) {
208-
throw new IOException("Internal error: mismatched buffer fill size");
209-
}
207+
// if (bytesWritten != currentBatchSize) {
208+
// throw new IOException("Internal error: mismatched buffer fill size");
209+
// }
210210

211211
out.write(buffer, 0, currentBatchSize);
212212
offset += currentBatchSize / elemSize;

src/main/python/systemds/context/systemds_context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(
8787
capture_stdout: bool = False,
8888
logging_level: int = 20,
8989
py4j_logging_level: int = 50,
90-
data_transfer_mode: int = 1,
90+
data_transfer_mode: int = 0,
9191
multi_pipe_enabled: bool = False,
9292
):
9393
"""Starts a new instance of SystemDSContext, in which the connection to a JVM systemds instance is handled
@@ -120,7 +120,9 @@ def __setup_data_transfer(self, data_transfer_mode=0, multi_pipe_enabled=False):
120120
self.__make_fifo_named_pipes(num_pipes)
121121
executor_pool, in_pipes, out_pipes = self.__init_pipes(num_pipes)
122122

123-
self._log.debug("Handshake done for {} IN / OUT Pipes".format(num_pipes))
123+
self._log.info(
124+
"Data transfer: Handshake done for {} IN / OUT Pipes".format(num_pipes)
125+
)
124126
self.executor_pool = executor_pool
125127
self.FIFO_PY2JAVA_PIPES = out_pipes
126128
self.FIFO_JAVA2PY_PIPES = in_pipes

src/main/python/tests/matrix/test_block_converter_unix_pipe.py renamed to src/main/python/tests/non_parallel_tests/test_block_converter_unix_pipe.py

File renamed without changes.

src/test/java/org/apache/sysds/test/component/utils/UnixPipeUtilsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public static class NonParameterizedTest {
101101

102102
@Test(expected = FileNotFoundException.class)
103103
public void testOpenInputFileNotFound() throws IOException {
104+
// instantiate class once for coverage
105+
new UnixPipeUtils();
106+
104107
// Create a path that does not exist
105108
File nonExistentFile = new File(folder.getRoot(), "nonexistent.pipe");
106109

src/test/java/org/apache/sysds/test/usertest/pythonapi/StartupTest.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.log4j.spi.LoggingEvent;
2525
import org.apache.sysds.api.PythonDMLScript;
2626
import org.apache.sysds.common.Types;
27+
import org.apache.sysds.runtime.DMLRuntimeException;
2728
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
2829
import org.apache.sysds.runtime.util.UnixPipeUtils;
2930
import org.apache.sysds.test.LoggingUtils;
@@ -166,7 +167,7 @@ public void testStartupCorrect() throws Exception {
166167

167168
@Test
168169
public void testDataTransfer() throws Exception {
169-
PythonDMLScript.main(new String[]{"-python", "4002"});
170+
PythonDMLScript.main(new String[]{"-python", "4003"});
170171
Thread.sleep(200);
171172
PythonDMLScript script = (PythonDMLScript) PythonDMLScript.GwS.getGateway().getEntryPoint();
172173

@@ -200,7 +201,7 @@ public void testDataTransfer() throws Exception {
200201

201202
@Test
202203
public void testDataTransferMultiPipes() throws Exception {
203-
PythonDMLScript.main(new String[]{"-python", "4002"});
204+
PythonDMLScript.main(new String[]{"-python", "4004"});
204205
Thread.sleep(200);
205206
PythonDMLScript script = (PythonDMLScript) PythonDMLScript.GwS.getGateway().getEntryPoint();
206207

@@ -229,6 +230,30 @@ public void testDataTransferMultiPipes() throws Exception {
229230
Thread.sleep(200);
230231
}
231232

233+
@Test(expected = DMLRuntimeException.class)
234+
public void testDataTransferNotInit1() throws Exception {
235+
PythonDMLScript.main(new String[]{"-python", "4005"});
236+
Thread.sleep(200);
237+
PythonDMLScript script = (PythonDMLScript) PythonDMLScript.GwS.getGateway().getEntryPoint();
238+
script.startReadingMbFromPipe(0, 2, 3, Types.ValueType.FP64);
239+
}
240+
241+
@Test(expected = DMLRuntimeException.class)
242+
public void testDataTransferNotInit2() throws Exception {
243+
PythonDMLScript.main(new String[]{"-python", "4006"});
244+
Thread.sleep(200);
245+
PythonDMLScript script = (PythonDMLScript) PythonDMLScript.GwS.getGateway().getEntryPoint();
246+
script.startWritingMbToPipe(0, null);
247+
}
248+
249+
@Test(expected = DMLRuntimeException.class)
250+
public void testDataTransferNotInit3() throws Exception {
251+
PythonDMLScript.main(new String[]{"-python", "4007"});
252+
Thread.sleep(200);
253+
PythonDMLScript script = (PythonDMLScript) PythonDMLScript.GwS.getGateway().getEntryPoint();
254+
script.startReadingMbFromPipes(new int[]{3,3}, 2, 3, Types.ValueType.FP64);
255+
}
256+
232257
@SuppressWarnings("removal")
233258
class NoExitSecurityManager extends SecurityManager {
234259
@Override
@@ -239,4 +264,20 @@ public void checkExit(int status) {
239264
throw new SecurityException("Intercepted exit()");
240265
}
241266
}
267+
268+
@Test(expected = DMLRuntimeException.class)
269+
public void testDataTransferMaxValue1() throws Exception {
270+
PythonDMLScript.main(new String[]{"-python", "4008"});
271+
Thread.sleep(200);
272+
PythonDMLScript script = (PythonDMLScript) PythonDMLScript.GwS.getGateway().getEntryPoint();
273+
script.startReadingMbFromPipe(0, Integer.MAX_VALUE, 3, Types.ValueType.FP64);
274+
}
275+
276+
@Test(expected = DMLRuntimeException.class)
277+
public void testDataTransferMaxValue2() throws Exception {
278+
PythonDMLScript.main(new String[]{"-python", "4009"});
279+
Thread.sleep(200);
280+
PythonDMLScript script = (PythonDMLScript) PythonDMLScript.GwS.getGateway().getEntryPoint();
281+
script.startReadingMbFromPipes(new int[]{3,3}, Integer.MAX_VALUE, 2, Types.ValueType.FP64);
282+
}
242283
}

0 commit comments

Comments
 (0)