Skip to content

Commit a451844

Browse files
jpnurmiclaude
andauthored
ci: speed up OOM tests with configurable memory limit (#1623)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c355e21 commit a451844

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ jobs:
235235
VS_GENERATOR_TOOLSET: ${{ matrix.VS_GENERATOR_TOOLSET }}
236236
SYSTEM_PYTHON: ${{ matrix.SYSTEM_PYTHON }}
237237
UTF8_TEST_CWD: ${{ matrix.UTF8_TEST_CWD }}
238+
SENTRY_TEST_OOM_LIMIT: "4095" # ~4GB, to speed up OOM tests
238239

239240
steps:
240241
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

examples/example.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,30 @@ trigger_stack_overflow()
384384
static void
385385
trigger_oom(void)
386386
{
387+
#ifdef SENTRY_PLATFORM_WINDOWS
388+
// Optionally limit process memory to trigger OOM faster.
389+
// Set SENTRY_TEST_OOM_LIMIT to the limit in MiB (e.g. "8192" for 8GB).
390+
// Without this, OOM exhausts all virtual memory which can take minutes.
391+
// Note: a Job Object limit only constrains user-mode allocations and
392+
// does not exhaust kernel pool memory like a real system-wide OOM would.
393+
const char *oom_limit = getenv("SENTRY_TEST_OOM_LIMIT");
394+
if (oom_limit) {
395+
unsigned long long limit = strtoull(oom_limit, NULL, 10) * 1024 * 1024;
396+
if (limit > 0 && limit <= SIZE_MAX) {
397+
HANDLE job = CreateJobObjectW(NULL, NULL);
398+
if (job) {
399+
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info = { 0 };
400+
info.BasicLimitInformation.LimitFlags
401+
= JOB_OBJECT_LIMIT_PROCESS_MEMORY;
402+
info.ProcessMemoryLimit = (size_t)limit;
403+
SetInformationJobObject(job, JobObjectExtendedLimitInformation,
404+
&info, sizeof(info));
405+
AssignProcessToJobObject(job, GetCurrentProcess());
406+
}
407+
}
408+
}
409+
#endif
410+
387411
size_t count = 1024;
388412
for (;;) {
389413
void *p = malloc(count);

0 commit comments

Comments
 (0)