1
0
mirror of https://github.com/facebookresearch/faiss.git synced 2025-06-03 21:54:02 +08:00
faiss/tests/test_oom_exception.py
Lucas Hosseini 39d7a33840 Make OOMException test Linux-only. ()
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1354

Test Plan: Imported from OSS

Reviewed By: mdouze

Differential Revision: D23292455

Pulled By: beauby

fbshipit-source-id: 50b096fd869724ef8e87f697887e8617522324e3
2020-08-24 06:46:52 -07:00

35 lines
1.1 KiB
Python
Executable File

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import sys
import faiss
import unittest
import platform
class TestOOMException(unittest.TestCase):
@unittest.skipIf(platform.system() != 'Linux',
'Test is Linux only.')
def test_outrageous_alloc(self):
import resource
# https://github.com/facebookresearch/faiss/issues/758
soft_as, hard_as = resource.getrlimit(resource.RLIMIT_AS)
# make sure that allocing more than 10G will fail
resource.setrlimit(resource.RLIMIT_AS, (10 * 1024 * 1024, hard_as))
try:
x = faiss.IntVector()
try:
x.resize(10**11) # 400 G of RAM
except MemoryError:
pass # good, that's what we expect
else:
assert False, "should raise exception"
finally:
resource.setrlimit(resource.RLIMIT_AS, (soft_as, hard_as))
if __name__ == '__main__':
unittest.main()