← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~adeuring/lazr.jobrunner/oops-when-memory-exceeded into lp:lazr.jobrunner

 

Abel Deuring has proposed merging lp:~adeuring/lazr.jobrunner/oops-when-memory-exceeded into lp:lazr.jobrunner.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~adeuring/lazr.jobrunner/oops-when-memory-exceeded/+merge/102841

A simple branch: A new test that an OOPS is recorded when a job needs more memory than allowed.
-- 
https://code.launchpad.net/~adeuring/lazr.jobrunner/oops-when-memory-exceeded/+merge/102841
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~adeuring/lazr.jobrunner/oops-when-memory-exceeded into lp:lazr.jobrunner.
=== modified file 'src/lazr/jobrunner/tests/test_celerytask.py'
--- src/lazr/jobrunner/tests/test_celerytask.py	2012-04-11 16:19:54 +0000
+++ src/lazr/jobrunner/tests/test_celerytask.py	2012-04-20 12:29:20 +0000
@@ -43,7 +43,9 @@
     )
 from lazr.jobrunner.tests.test_jobrunner import (
     FakeJob,
+    OOPSTestRepository,
     )
+import oops
 
 
 def get_root():
@@ -234,6 +236,33 @@
         self.assertEqual(1024 ** 3, job.current_memory_limit)
         self.assertEqual(start_limits, getrlimit(RLIMIT_AS))
 
+    def test_memory_limit_exceeded(self):
+        # If a job exceeds its memory limit, an OOPS is recorded.
+        MEMORY_LIMIT = 1024 ** 3
+
+        class RunOutOfMemoryJob(FakeJob):
+
+            def run(self):
+                super(RunOutOfMemoryJob, self).run()
+                'x' * MEMORY_LIMIT
+
+        js = FakeJobSource()
+        job = RunOutOfMemoryJob(10)
+        js.jobs[10] = job
+        js.memory_limit = MEMORY_LIMIT
+        task = RunJob()
+        oops_config = oops.Config()
+        oops_repository = OOPSTestRepository()
+        oops_config.publishers.append(oops_repository.publish)
+        task.oops_config = oops_config
+        task.job_source = js
+        task.run(10)
+        # There is exactly one OOPS report.
+        self.assertEqual(1, len(oops_repository.oopses))
+        # This OOPS describes a MemoryError.
+        oops_report = oops_repository.oopses.values()[0]
+        self.assertEqual('MemoryError', oops_report['type'])
+
     def test_acquires_lease(self):
         js = self.makeFakeJobSource()
         self.assertFalse(js.jobs[10].lease_held)