Skip to content

Commit 7ec57a9

Browse files
kalyazinclaude
andcommitted
test(orch): cover the memfd identity-offset source
Assert MemfdIdentitySource serves dirty pages from the memfd at identity offsets while mapped, and reports BytesNotAvailableError once the memfd is released. Signed-off-by: Nikita Kalyazin <nikita.kalyazin@e2b.dev> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a4cee7e commit 7ec57a9

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

packages/orchestrator/pkg/sandbox/block/memfd_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,31 @@ func TestDedupedMemfdCache_InflightConcurrentDrainRace(t *testing.T) {
395395
default:
396396
}
397397
}
398+
399+
// MemfdIdentitySource serves dirty pages from the memfd at identity offsets
400+
// while it is mapped, and reports BytesNotAvailableError once it is released so
401+
// the caller falls back to the drained cache (via the swapped-in deduped header).
402+
func TestMemfdIdentitySource_ServesThenReleases(t *testing.T) {
403+
t.Parallel()
404+
405+
ps := int64(header.PageSize)
406+
memfd, data := newTestMemfd(t, ps*4)
407+
d := &DedupedMemfdCache{done: utils.NewSetOnce[*Cache](), memfd: memfd}
408+
src := NewMemfdIdentitySource(d, ps*4)
409+
410+
for _, page := range []int64{0, 2, 3} {
411+
b := make([]byte, ps)
412+
n, err := src.ReadAt(b, page*ps)
413+
require.NoError(t, err)
414+
require.Equal(t, int(ps), n)
415+
require.Equal(t, data[page*ps:(page+1)*ps], b)
416+
}
417+
require.True(t, src.IsCached(t.Context(), 0, ps*4))
418+
419+
require.NoError(t, d.releaseMemfd())
420+
421+
_, err := src.ReadAt(make([]byte, ps), 0)
422+
var bna BytesNotAvailableError
423+
require.ErrorAs(t, err, &bna)
424+
require.False(t, src.IsCached(t.Context(), 0, ps))
425+
}

0 commit comments

Comments
 (0)