First commit Go counter service

This commit is contained in:
Dimitrije Dimitrijevic
2026-10-15 02:12:18 +02:00
commit c43ff17627
59 changed files with 11205 additions and 0 deletions
@@ -0,0 +1,36 @@
package store
import (
"context"
"testing"
"time"
"github.com/redis/go-redis/v9"
"migadu_counters/internal/config"
)
func TestReview_TimeoutAfterWriteStillCounts(t *testing.T) {
st, err := New(config.RedisConfig{WriteAddr: "127.0.0.1:16401", PoolSize: 4, TimeoutMS: 500})
if err != nil {
t.Fatal(err)
}
defer st.Close()
admin := redis.NewClient(&redis.Options{Addr: "127.0.0.1:16401"})
defer admin.Close()
key := "cnt/A/review@example.com/d/2026-10-14/o"
admin.Del(context.Background(), key)
admin.Set(context.Background(), key, "99", 0) // limit 100: next increment crosses
// warm the pool
if err := st.Ping(context.Background()); err != nil {
t.Fatal(err)
}
go admin.Do(context.Background(), "DEBUG", "SLEEP", "1") // server stall > timeout_ms
time.Sleep(50 * time.Millisecond)
_, err = st.Incr(context.Background(), []string{key}, 1)
t.Logf("Incr error: %v", err)
time.Sleep(1500 * time.Millisecond)
v, _ := admin.Get(context.Background(), key).Result()
t.Logf("key after the 'failed' Incr: %s", v)
admin.Del(context.Background(), key)
}