Files
tasks/service/matching/task_tracker_test.go
zeekay 40351cce6f rip: delete temporal fork — native ZAP-only tasksd
Goes from 135 MB binary with 1153 files importing go.temporal.io and 224
importing google.golang.org/grpc to a 10 MB native binary with ZERO of
either.

Deleted:
- tasks/, tasktests/, service/, chasm/, client/, api/, proto/, tools/
- cmd/tools/, components/, docker/
- schema/{cassandra,elasticsearch,mysql,postgresql,sqlite}/
- 40 tainted common/ subdirs + 7 top-level common files
- tests/testutils (no longer referenced after surviving deps drop common)

New cmd/tasksd (~100 lines) boots tasks.Embed (zap.Node) + http.Server.
New pkg/tasks/embed.go registers ZAP handlers for the SDK opcode surface
(0x0060-0x00A5). Workflow handlers return a 501 "not yet implemented"
envelope; native engine lands behind this contract.

Build:  go build ./cmd/tasksd → 10 MB
Vet:    go vet ./... → clean
Boot:   tasksd --zap-port 9999 --http :7243
Probes: /healthz, /v1/tasks/health → 200
UI:     /_/tasks/, / → 200 (embedded Vite bundle)
ZAP:    _tasks._tcp on :9999 (mDNS disabled; direct connect)

go.mod: tidy. No go.temporal.io. No google.golang.org/grpc.
2026-04-26 14:06:21 -07:00

57 lines
2.1 KiB
Go

package matching
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"go.temporal.io/server/common/clock"
)
func TestAddTasksRate(t *testing.T) {
// define a fake clock and it's time for testing
timeSource := clock.NewEventTimeSource()
currentTime := time.Now()
timeSource.Update(currentTime)
tr := newTaskTracker(timeSource, 5*time.Second, 30*time.Second)
// mini windows will have the following format : (start time, end time)
// (0 - 4), (5 - 9), (10 - 14), (15 - 19), (20 - 24), (25 - 29), (30 - 34), ...
// rate should be zero when no time is passed
require.Equal(t, float32(0), tr.rate()) // time: 0
tr.inc(100)
require.Equal(t, float32(0), tr.rate()) // still zero because no time is passed
// tasks should be placed in the first mini-window
timeSource.Advance(1 * time.Second) // time: 1 second
require.InEpsilon(t, float32(100), tr.rate(), 0.001) // 100 tasks added in 1 second = 100 / 1 = 100
// tasks should be placed in the second mini-window with 6 total seconds elapsed
timeSource.Advance(5 * time.Second) // time: 6 second
tr.inc(100)
tr.inc(100)
require.InEpsilon(t, float32(50), tr.rate(), 0.001) // (100 + 200) tasks added in 6 seconds = 300/6 = 50
timeSource.Advance(24 * time.Second) // time: 30 second
tr.inc(100)
tr.inc(100)
tr.inc(100)
require.InEpsilon(t, float32(20), tr.rate(), 0.001) // (100 + 200 + 300) tasks added in (30 + 0 (current window)) seconds = 600/30 = 20
// this should clear out the first mini-window of 100 tasks
timeSource.Advance(5 * time.Second) // time: 35 second
tr.inc(10)
require.InEpsilon(t, float32(17), tr.rate(), 0.001) // (10 + 200 + 300) tasks added in (30 + 0 (current window)) seconds = 510/30 = 17
// this should clear out the second and third mini-windows
timeSource.Advance(15 * time.Second) // time: 50 second
tr.inc(10)
require.InEpsilon(t, float32(10.666667), tr.rate(), 0.001) // (10 + 10 + 300) tasks added in (30 + 0 (current window)) seconds = 320/30 = 10.66
// a minute passes and no tasks are added
timeSource.Advance(60 * time.Second)
require.Equal(t, float32(0), tr.rate()) // 0 tasks have been added in the last 30 seconds
}