refactor: Remove Token management and integrate Redis for authentication
- Deleted the Token model and its repository, transitioning to a Redis-based token management system. - Updated the service layer to utilize Redis for token storage, enhancing performance and scalability. - Refactored the container to remove TokenRepository and integrate the new token service. - Cleaned up the Dockerfile and other files by removing unnecessary whitespace and comments. - Enhanced error handling and logging for Redis initialization and usage.
This commit is contained in:
65
internal/task/runner_test.go
Normal file
65
internal/task/runner_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type mockTask struct {
|
||||
name string
|
||||
interval time.Duration
|
||||
err error
|
||||
runCount *atomic.Int32
|
||||
}
|
||||
|
||||
func (m *mockTask) Name() string { return m.name }
|
||||
func (m *mockTask) Interval() time.Duration { return m.interval }
|
||||
func (m *mockTask) Run(ctx context.Context) error {
|
||||
if m.runCount != nil {
|
||||
m.runCount.Add(1)
|
||||
}
|
||||
return m.err
|
||||
}
|
||||
|
||||
func TestRunner_StartAndWait(t *testing.T) {
|
||||
runCount := &atomic.Int32{}
|
||||
task := &mockTask{name: "ok", interval: 20 * time.Millisecond, runCount: runCount}
|
||||
runner := NewRunner(zap.NewNop(), task)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
runner.Start(ctx)
|
||||
|
||||
time.Sleep(60 * time.Millisecond)
|
||||
cancel()
|
||||
runner.Wait()
|
||||
|
||||
if runCount.Load() == 0 {
|
||||
t.Fatalf("expected task to run at least once")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunner_RunErrorLogged(t *testing.T) {
|
||||
runCount := &atomic.Int32{}
|
||||
task := &mockTask{name: "err", interval: 10 * time.Millisecond, err: errors.New("boom"), runCount: runCount}
|
||||
runner := NewRunner(zap.NewNop(), task)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
runner.Start(ctx)
|
||||
time.Sleep(25 * time.Millisecond)
|
||||
cancel()
|
||||
runner.Wait()
|
||||
|
||||
if runCount.Load() == 0 {
|
||||
t.Fatalf("expected task to be attempted")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user