Skip to content

Commit

Permalink
chore: lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
pancsta committed Sep 11, 2024
1 parent 18f263f commit 8d2993a
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 68 deletions.
1 change: 0 additions & 1 deletion examples/benchmark_grpc/client_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func BenchmarkClientLocal(b *testing.B) {
// 2. getter: get a value from the worker
// 3. processing: call an operation based on the value
worker.Subscribe(func() {

// loop
i++
if i > limit {
Expand Down
1 change: 0 additions & 1 deletion examples/benchmark_grpc/server_arpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type WorkerArpcServer struct {
func NewWorkerArpcServer(
ctx context.Context, addr string, worker *Worker,
) (*WorkerArpcServer, error) {

// validate
if worker == nil {
return nil, errors.New("worker is nil")
Expand Down
1 change: 0 additions & 1 deletion pkg/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,6 @@ func (m *Machine) processHandlers(e *Event) (Result, bool) {
// returns from State and End handlers are ignored
default:
if !ret {

return Canceled, handlerCalled
}
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/machine/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,6 @@ type (
IndexWhenArgs map[string][]*WhenArgsBinding
// IndexStateCtx is a map of (single) state names to a context cancel function
IndexStateCtx map[string][]context.CancelFunc
// map of (single) state names to an event channel
indexEventCh map[string][]chan *Event
)

type WhenBinding struct {
Expand Down
9 changes: 0 additions & 9 deletions pkg/machine/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package machine

import (
"context"
"os"
"testing"
"time"

Expand Down Expand Up @@ -129,11 +128,3 @@ func TestIsActiveTick(t *testing.T) {
assert.False(t, IsActiveTick(6548734))
assert.True(t, IsActiveTick(6548735))
}

func fileExists(filePath string) bool {
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
return false
}
return err == nil
}
3 changes: 2 additions & 1 deletion pkg/machine/popup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"testing"
"time"

am "github.com/pancsta/asyncmachine-go/pkg/machine"
"github.com/stretchr/testify/assert"

am "github.com/pancsta/asyncmachine-go/pkg/machine"
)

func NewPopupMachine(ctx context.Context) *am.Machine {
Expand Down
1 change: 0 additions & 1 deletion pkg/machine/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ func (t *Transition) emitEvents() Result {

// AUTO STATES
if result == Canceled {

t.Accepted = false
} else if hasStateChanged && !t.IsAuto() {

Expand Down
2 changes: 0 additions & 2 deletions pkg/machine/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (h *History) AC(e *Event) {

func (h *History) AExit(e *Event) {
h.event("AExit")

}

func (h *History) AA(e *Event) {
Expand Down Expand Up @@ -64,7 +63,6 @@ func (h *History) AnyB(e *Event) {

func (h *History) BExit(e *Event) {
h.event("BExit")

}

func (h *History) BD(e *Event) {
Expand Down
8 changes: 5 additions & 3 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ type Client struct {
}

// interfaces
var _ clientRpcMethods = &Client{}
var _ clientServerMethods = &Client{}
var (
_ clientRpcMethods = &Client{}
_ clientServerMethods = &Client{}
)

func NewClient(
ctx context.Context, workerAddr string, id string, stateStruct am.Struct,
Expand Down Expand Up @@ -182,7 +184,7 @@ func (c *Client) HandshakingState(e *am.Event) {

go func() {
// call rpc
var resp = &RespHandshake{}
resp := &RespHandshake{}
if !c.call(ctx, rpcnames.Handshake.Encode(), Empty{}, resp) {
return
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/rpc/rpc_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
type S = am.S

// type A = am.A
type State = am.State
type Struct = am.Struct
type (
State = am.State
Struct = am.Struct
)

func init() {
if os.Getenv("AM_TEST_DEBUG") != "" {
Expand Down
1 change: 0 additions & 1 deletion pkg/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ func NewTest(
t *testing.T, ctx context.Context, worker *am.Machine,
disposeMeter <-chan struct{}, clockInterval *time.Duration,
) (<-chan int64, *am.Machine, *Server, *Client) {

// read env
amDbgAddr := os.Getenv("AM_DBG_ADDR")
logLvl := am.EnvLogLevel("")
Expand Down
6 changes: 4 additions & 2 deletions pkg/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ type Server struct {
}

// interfaces
var _ serverRpcMethods = &Server{}
var _ clientServerMethods = &Server{}
var (
_ serverRpcMethods = &Server{}
_ clientServerMethods = &Server{}
)

func NewServer(
ctx context.Context, addr string, id string, worker *am.Machine,
Expand Down
5 changes: 0 additions & 5 deletions pkg/rpc/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ var (

// wrapping error setters

func errResponse(mach *am.Machine, err error) {
mach.AddErr(fmt.Errorf("%w: %w", ErrInvalidResp, err), nil)
}

func errResponseStr(mach *am.Machine, msg string) {
mach.AddErr(fmt.Errorf("%w: %s", ErrInvalidResp, msg), nil)
}
Expand All @@ -144,7 +140,6 @@ func errNetwork(mach *am.Machine, err error) {

// errAuto detects sentinels from error msgs and wraps.
func errAuto(mach *am.Machine, msg string, err error) {

// detect group from text
var errGroup error
if strings.HasPrefix(err.Error(), "gob: ") {
Expand Down
3 changes: 2 additions & 1 deletion pkg/rpc/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"testing"

"github.com/lithammer/dedent"
"github.com/stretchr/testify/assert"

am "github.com/pancsta/asyncmachine-go/pkg/machine"
"github.com/pancsta/asyncmachine-go/pkg/types"
"github.com/stretchr/testify/assert"
)

func assertStates(t *testing.T, m types.MachineApi, expected am.S,
Expand Down
29 changes: 2 additions & 27 deletions pkg/rpc/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Worker struct {
indexWhen am.IndexWhen
indexWhenTime am.IndexWhenTime
// TODO indexWhenArgs
indexWhenArgs am.IndexWhenArgs
whenDisposed chan struct{}
// indexWhenArgs am.IndexWhenArgs
whenDisposed chan struct{}
}

// Worker implements MachineApi
Expand Down Expand Up @@ -1028,7 +1028,6 @@ func (w *Worker) processWhenTimeBindings(timeBefore am.Time) {
// collect all the ticked states
all := am.S{}
for idx, t := range timeBefore {

// if changed, collect to check
if w.clockTime[idx] != t {
all = append(all, w.stateNames[idx])
Expand All @@ -1037,7 +1036,6 @@ func (w *Worker) processWhenTimeBindings(timeBefore am.Time) {

// check all the bindings for all the ticked states
for _, s := range all {

for k, binding := range indexWhenTime[s] {

// check if the requested time has passed
Expand Down Expand Up @@ -1133,11 +1131,6 @@ func j(states []string) string {
return strings.Join(states, " ")
}

// jw joins state names into a single string with a separator.
func jw(states []string, sep string) string {
return strings.Join(states, sep)
}

// disposeWithCtx handles early binding disposal caused by a canceled context.
// It's used by most of "when" methods.
func disposeWithCtx[T comparable](
Expand Down Expand Up @@ -1215,24 +1208,6 @@ func slicesEvery[S1 ~[]E, S2 ~[]E, E comparable](col1 S1, col2 S2) bool {
return true
}

func slicesFilter[S ~[]E, E any](coll S, fn func(item E, i int) bool) S {
var ret S
for i, el := range coll {
if fn(el, i) {
ret = append(ret, el)
}
}
return ret
}

func slicesReverse[S ~[]E, E any](coll S) S {
ret := make(S, len(coll))
for i := range coll {
ret[i] = coll[len(coll)-1-i]
}
return ret
}

func slicesUniq[S ~[]E, E comparable](coll S) S {
var ret S
for _, el := range coll {
Expand Down
4 changes: 1 addition & 3 deletions pkg/states/ss_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ var States = am.Struct{

// Groups of mutually exclusive states.

var (
GroupConnected = S{Connecting, Connected, Disconnecting, Disconnected}
)
var GroupConnected = S{Connecting, Connected, Disconnecting, Disconnected}

// #region boilerplate defs

Expand Down
5 changes: 3 additions & 2 deletions pkg/telemetry/prometheus/prometheus.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package prometheus provides Prometheus metrics for asyncamachine.
// Package prometheus provides Prometheus metrics for asyncmachine.
// Metrics are collected from machine's transitions and states.
package prometheus

Expand Down Expand Up @@ -391,7 +391,8 @@ func TransitionsToPrometheus(
metrics.RelAmount.Set(float64(relCount))
metrics.RefStatesAmount.Set(float64(stateRefCount))

mach.Tracers = append(mach.Tracers, &promTracer{m: metrics})
metrics.tracer = &promTracer{m: metrics}
mach.Tracers = append(mach.Tracers, metrics.tracer)

return metrics
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ type DbgMsgTx struct {
func (d *DbgMsgTx) Clock(statesIndex am.S, state string) uint64 {
idx := lo.IndexOf(statesIndex, state)
return d.Clocks[idx]

}

func (d *DbgMsgTx) Is(statesIndex am.S, states am.S) bool {

for _, state := range states {
idx := lo.IndexOf(statesIndex, state) //nolint:typecheck
if idx == -1 {
Expand Down
1 change: 0 additions & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
// MachineApi is a subset of `pkg/machine#Machine` for alternative
// implementations.
type MachineApi interface {

// ///// REMOTE

// Mutations (remote)
Expand Down
1 change: 0 additions & 1 deletion tools/debugger/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ func (d *Debugger) ToggleFilterState(_ *am.Event) {
}

func (d *Debugger) SwitchingClientTxState(e *am.Event) {

clientID, _ := e.Args["Client.id"].(string)
cursorTx, _ := e.Args["Client.cursorTx"].(int)
ctx := d.Mach.NewStateCtx(ss.SwitchingClientTx)
Expand Down

0 comments on commit 8d2993a

Please sign in to comment.