From 4419890c01e7fafa0243af255a8248e5724522b8 Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Fri, 1 Dec 2017 00:41:50 -0800 Subject: [PATCH 1/2] Remove symlink & just copy postBuild file instead Temp fix for https://github.com/jupyter/repo2docker/issues/160. Also includes a test to prevent drift --- tests/memlimit.py | 18 ++++++++++++++++ tests/memlimit/dockerfile/postBuild | 5 +++++ tests/memlimit/non-dockerfile/postBuild | 28 ++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) mode change 120000 => 100755 tests/memlimit/non-dockerfile/postBuild diff --git a/tests/memlimit.py b/tests/memlimit.py index 7f7f1bb3..9a78141e 100644 --- a/tests/memlimit.py +++ b/tests/memlimit.py @@ -79,3 +79,21 @@ def test_memlimit_dockerfile_fail(): 512, 256 ) + + +def test_memlimit_same_postbuild(): + """ + Validate that the postBuild files for dockerfile & nondockerfile are same + + Until https://github.com/jupyter/repo2docker/issues/160 gets fixed. + """ + basedir = os.path.dirname(__file__) + filepaths = [ + os.path.join(basedir, 'memlimit', t, "postBuild") + for t in ("dockerfile", "non-dockerfile") + ] + file_contents = [] + for fp in filepaths: + with open(fp) as f: + file_contents.append(f.read()) + assert all(c == file_contents[0] for c in file_contents) diff --git a/tests/memlimit/dockerfile/postBuild b/tests/memlimit/dockerfile/postBuild index 38a2e806..bb3d7d65 100755 --- a/tests/memlimit/dockerfile/postBuild +++ b/tests/memlimit/dockerfile/postBuild @@ -4,6 +4,11 @@ Simplest program that tries to allocate a large amount of RAM. malloc lies on Linux by default, so we use memset to force the kernel to actually give us real memory. + +NOTE: This file has to be duplicated & present in all the following locations: + - tests/memlimit/dockerfile/postBuild + - tests/memlimit/dockerfile/postBuild +See https://github.com/jupyter/repo2docker/issues/160 for reason """ from ctypes import cdll, c_void_p, memset import os diff --git a/tests/memlimit/non-dockerfile/postBuild b/tests/memlimit/non-dockerfile/postBuild deleted file mode 120000 index 874b6793..00000000 --- a/tests/memlimit/non-dockerfile/postBuild +++ /dev/null @@ -1 +0,0 @@ -../dockerfile/postBuild \ No newline at end of file diff --git a/tests/memlimit/non-dockerfile/postBuild b/tests/memlimit/non-dockerfile/postBuild new file mode 100755 index 00000000..bb3d7d65 --- /dev/null +++ b/tests/memlimit/non-dockerfile/postBuild @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +""" +Simplest program that tries to allocate a large amount of RAM. + +malloc lies on Linux by default, so we use memset to force the +kernel to actually give us real memory. + +NOTE: This file has to be duplicated & present in all the following locations: + - tests/memlimit/dockerfile/postBuild + - tests/memlimit/dockerfile/postBuild +See https://github.com/jupyter/repo2docker/issues/160 for reason +""" +from ctypes import cdll, c_void_p, memset +import os + +libc = cdll.LoadLibrary("libc.so.6") +libc.malloc.restype = c_void_p + +with open('mem_allocate_mb') as f: + mem_allocate_mb = int(f.read().strip()) + +size = 1024 * 1024 * mem_allocate_mb +print("trying to allocate {}MB".format(mem_allocate_mb)) + +ret = libc.malloc(size) + +memset(ret, 0, size) From b4f012799b166552b7afa23b83ae34962b530f99 Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Fri, 1 Dec 2017 00:46:29 -0800 Subject: [PATCH 2/2] More idiomatic way of checking if all items on a list are same --- tests/memlimit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/memlimit.py b/tests/memlimit.py index 9a78141e..c830cb4a 100644 --- a/tests/memlimit.py +++ b/tests/memlimit.py @@ -96,4 +96,5 @@ def test_memlimit_same_postbuild(): for fp in filepaths: with open(fp) as f: file_contents.append(f.read()) - assert all(c == file_contents[0] for c in file_contents) + # Make sure they're all the same + assert len(set(file_contents)) == 1