6 "github.com/stretchr/testify/require"
9func TestVersionedMap_Set(t *testing.T) {
12 vm := NewVersionedMap[string, int]()
13 require.Equal(t, uint64(0), vm.Version())
16 require.Equal(t, uint64(1), vm.Version())
18 value, ok := vm.Get("key1")
20 require.Equal(t, 42, value)
23func TestVersionedMap_Del(t *testing.T) {
26 vm := NewVersionedMap[string, int]()
28 initialVersion := vm.Version()
31 require.Equal(t, initialVersion+1, vm.Version())
33 _, ok := vm.Get("key1")
37func TestVersionedMap_VersionIncrement(t *testing.T) {
40 vm := NewVersionedMap[string, int]()
41 initialVersion := vm.Version()
43 // Setting a value should increment the version
45 require.Equal(t, initialVersion+1, vm.Version())
47 // Deleting a value should increment the version
49 require.Equal(t, initialVersion+2, vm.Version())
51 // Deleting a non-existent key should still increment the version
53 require.Equal(t, initialVersion+3, vm.Version())
56func TestVersionedMap_ConcurrentAccess(t *testing.T) {
59 vm := NewVersionedMap[int, int]()
60 const numGoroutines = 100
61 const numOperations = 100
64 initialVersion := vm.Version()
66 // Perform concurrent Set and Del operations
67 for i := range numGoroutines {
69 for j := range numOperations {
70 key := id*numOperations + j
77 // Wait for operations to complete by checking the version
78 // This is a simplified check - in a real test you might want to use sync.WaitGroup
79 expectedMinVersion := initialVersion + uint64(numGoroutines*numOperations*2)
81 // Allow some time for operations to complete
82 for vm.Version() < expectedMinVersion {
83 // Busy wait - in a real test you'd use proper synchronization
86 // Final version should be at least the expected minimum
87 require.GreaterOrEqual(t, vm.Version(), expectedMinVersion)
88 require.Equal(t, 0, vm.Len())
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list