Port envd from e2b with internalized shared packages and Connect RPC
- Copy envd source from e2b-dev/infra, internalize shared dependencies
into envd/internal/shared/ (keys, filesystem, id, smap, utils)
- Switch from gRPC to Connect RPC for all envd services
- Update module paths to git.omukk.dev/wrenn/{sandbox,sandbox/envd}
- Add proto specs (process, filesystem) with buf-based code generation
- Implement full envd: process exec, filesystem ops, port forwarding,
cgroup management, MMDS integration, and HTTP API
- Update main module dependencies (firecracker SDK, pgx, goose, etc.)
- Remove placeholder .gitkeep files replaced by real implementations
This commit is contained in:
76
envd/internal/utils/atomic_test.go
Normal file
76
envd/internal/utils/atomic_test.go
Normal file
@ -0,0 +1,76 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAtomicMax_NewAtomicMax(t *testing.T) {
|
||||
t.Parallel()
|
||||
am := NewAtomicMax()
|
||||
require.NotNil(t, am)
|
||||
require.Equal(t, int64(0), am.val)
|
||||
}
|
||||
|
||||
func TestAtomicMax_SetToGreater_InitialValue(t *testing.T) {
|
||||
t.Parallel()
|
||||
am := NewAtomicMax()
|
||||
|
||||
// Should succeed when newValue > current
|
||||
assert.True(t, am.SetToGreater(10))
|
||||
assert.Equal(t, int64(10), am.val)
|
||||
}
|
||||
|
||||
func TestAtomicMax_SetToGreater_EqualValue(t *testing.T) {
|
||||
t.Parallel()
|
||||
am := NewAtomicMax()
|
||||
am.val = 10
|
||||
|
||||
// Should succeed when newValue > current
|
||||
assert.True(t, am.SetToGreater(20))
|
||||
assert.Equal(t, int64(20), am.val)
|
||||
}
|
||||
|
||||
func TestAtomicMax_SetToGreater_GreaterValue(t *testing.T) {
|
||||
t.Parallel()
|
||||
am := NewAtomicMax()
|
||||
am.val = 10
|
||||
|
||||
// Should fail when newValue < current, keeping the max value
|
||||
assert.False(t, am.SetToGreater(5))
|
||||
assert.Equal(t, int64(10), am.val)
|
||||
}
|
||||
|
||||
func TestAtomicMax_SetToGreater_NegativeValues(t *testing.T) {
|
||||
t.Parallel()
|
||||
am := NewAtomicMax()
|
||||
am.val = -5
|
||||
|
||||
assert.True(t, am.SetToGreater(-2))
|
||||
assert.Equal(t, int64(-2), am.val)
|
||||
}
|
||||
|
||||
func TestAtomicMax_SetToGreater_Concurrent(t *testing.T) {
|
||||
t.Parallel()
|
||||
am := NewAtomicMax()
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Run 100 goroutines trying to update the value concurrently
|
||||
numGoroutines := 100
|
||||
wg.Add(numGoroutines)
|
||||
|
||||
for i := range numGoroutines {
|
||||
go func(val int64) {
|
||||
defer wg.Done()
|
||||
am.SetToGreater(val)
|
||||
}(int64(i))
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// The final value should be 99 (the maximum value)
|
||||
assert.Equal(t, int64(99), am.val)
|
||||
}
|
||||
Reference in New Issue
Block a user