MCPcopy Create free account
hub / github.com/aceld/zinx / TestGetOrSetFuncLock

Function TestGetOrSetFuncLock

zutils/shard_lock_map_test.go:559–583  ·  view source on GitHub ↗

TestGetOrSetFuncLock tests the GetOrSetFuncLock method

(t *testing.T)

Source from the content-addressed store, hash-verified

557
558// TestGetOrSetFuncLock tests the GetOrSetFuncLock method
559func TestGetOrSetFuncLock(t *testing.T) {
560 slm := NewShardLockMaps()
561
562 // Test setting a new value with function in lock
563 value, isSet := slm.GetOrSetFuncLock("key1", func(key string) interface{} {
564 return "locked_" + key
565 })
566 if !isSet {
567 t.Error("Expected isSet to be true for new key")
568 }
569 if value != "locked_key1" {
570 t.Error("Expected value to be 'locked_key1'")
571 }
572
573 // Test getting existing value
574 value, isSet = slm.GetOrSetFuncLock("key1", func(key string) interface{} {
575 return "should_not_be_called"
576 })
577 if isSet {
578 t.Error("Expected isSet to be false for existing key")
579 }
580 if value != "locked_key1" {
581 t.Error("Expected value to be 'locked_key1'")
582 }
583}
584
585// TestMGet tests the MGet method
586func TestMGet(t *testing.T) {

Callers

nothing calls this directly

Calls 3

GetOrSetFuncLockMethod · 0.95
NewShardLockMapsFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected