Skip to content

Commit

Permalink
Merge 96f1e91 into bac268e
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW authored Dec 4, 2024
2 parents bac268e + 96f1e91 commit cbdb8b4
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 13 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ jobs:

- name: Run octocov
uses: k1LoW/octocov-action@v1
race:
name: Check race
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true

- name: Set up Chrome
uses: browser-actions/setup-chrome@latest

- name: Run tests
run: make race
lint:
name: Lint
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ci: depsdev test-all
test: cert
go test ./... -coverprofile=coverage.out -covermode=count

race:
race: cert
go test ./... -race

test-integration: cert
Expand Down
8 changes: 8 additions & 0 deletions dbg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"strconv"
"strings"
"sync"

"github.com/elk-language/go-prompt"
pstrings "github.com/elk-language/go-prompt/strings"
Expand Down Expand Up @@ -48,6 +49,7 @@ type dbg struct {
breakpoints []breakpoint
opn *operatorN
pp *pp.PrettyPrinter
mu sync.Mutex
}

func newDBG(enable bool) *dbg {
Expand Down Expand Up @@ -340,6 +342,12 @@ L:
return nil
}

func (d *dbg) setOperatorN(opn *operatorN) {
d.mu.Lock()
defer d.mu.Unlock()
d.opn = opn
}

// storeKeys lists all keys in the store.
func storeKeys(store map[string]any) []string {
const storeKeySep = "."
Expand Down
5 changes: 5 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"
"strconv"
"strings"
"sync"

"github.com/expr-lang/expr"
"github.com/expr-lang/expr/ast"
Expand All @@ -28,13 +29,17 @@ var baseTreePrinterOptions = []exprtrace.TreePrinterOption{
exprtrace.WithOnCallNodeHook(onPrintTraceCallNode),
}

var evalMu sync.Mutex //FIXME: remove global mutex

func EvalWithTrace(e string, store exprtrace.EvalEnv) (*exprtrace.EvalResult, error) {
e = trimDeprecatedComment(e)
var result *exprtrace.EvalResult

trace := exprtrace.NewStore()
tracer := exprtrace.NewTracer(trace, store)
evalMu.Lock()
program, err := expr.Compile(e, tracer.Patches()...)
evalMu.Unlock()
if err != nil {
return nil, fmt.Errorf("eval error: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/k1LoW/protoresolv v0.1.1
github.com/k1LoW/repin v0.3.4
github.com/k1LoW/sshc/v4 v4.2.0
github.com/k1LoW/stopw v0.9.0
github.com/k1LoW/stopw v0.9.1
github.com/k1LoW/urlfilepath v0.1.0
github.com/k1LoW/waitmap v1.4.1
github.com/lestrrat-go/backoff/v2 v2.0.8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,8 @@ github.com/k1LoW/repin v0.3.4 h1:xcNuBBc/ISHUNBzjXNTCux4OYZND5ZMiyz4SrRtpDhg=
github.com/k1LoW/repin v0.3.4/go.mod h1:1abQMGdYFegTCsxbhZ3O5P8aKENYS37UhQKwKYKiYkg=
github.com/k1LoW/sshc/v4 v4.2.0 h1:Bvq2L4q9u25N8Rti70sKC0BuGOcfFMylvWVz7JIdeGM=
github.com/k1LoW/sshc/v4 v4.2.0/go.mod h1:fk2F2njae6tWSk5Or4064cWenaiBXk9z5L6IxHyUSCo=
github.com/k1LoW/stopw v0.9.0 h1:7P2o9vVWZAKXXQtTAAcf3WL/bn3ETahBa2YbguuvpNc=
github.com/k1LoW/stopw v0.9.0/go.mod h1:LdlT91WpGPwBvhmqgRfYwZ/HD2wpGYTcKiHyNbntQiE=
github.com/k1LoW/stopw v0.9.1 h1:IfH1UpZ2J7ZDJckl7EFmAueueH5fzSX71V0FA6L6TUQ=
github.com/k1LoW/stopw v0.9.1/go.mod h1:LdlT91WpGPwBvhmqgRfYwZ/HD2wpGYTcKiHyNbntQiE=
github.com/k1LoW/urlfilepath v0.1.0 h1:JU2FJISuw9oGHy0SAC85O85pnYS3/Z2r0TLlIpy215E=
github.com/k1LoW/urlfilepath v0.1.0/go.mod h1:j4lhxDjaRXJ+X/NF0dDCF2TM3/WTv96SbKLfLZlgoPM=
github.com/k1LoW/waitmap v1.4.1 h1:kCfJGvr6Icd1F2F/udY10FA9BVdzGLabPGFd6FTLAYw=
Expand Down
15 changes: 8 additions & 7 deletions http_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ type openAPI3Validator struct {
skipValidateResponse bool
doc libopenapi.Document
validator validator.Validator
mu sync.Mutex
}

func newOpenAPI3Validator(c *httpRunnerConfig) (*openAPI3Validator, error) {
Expand Down Expand Up @@ -186,22 +185,23 @@ func (v *openAPI3Validator) ValidateRequest(ctx context.Context, req *http.Reque
if v.skipValidateRequest {
return nil
}
v.mu.Lock()
globalOpenAPI3DocRegistoryMu.Lock()
_, errs := v.validator.ValidateHttpRequest(req)
if len(errs) == 0 {
v.mu.Unlock()
globalOpenAPI3DocRegistoryMu.Unlock()
return nil
}
{
// renew validator (workaround)
// ref: https://github.com/k1LoW/runn/issues/882
vv, errrs := validator.NewValidator(v.doc)
if len(errrs) > 0 {
globalOpenAPI3DocRegistoryMu.Unlock()
return errors.Join(errrs...)
}
v.validator = vv
}
v.mu.Unlock()
globalOpenAPI3DocRegistoryMu.Unlock()
var err error
for _, e := range errs {
// nullable type workaround.
Expand All @@ -224,22 +224,23 @@ func (v *openAPI3Validator) ValidateResponse(ctx context.Context, req *http.Requ
if v.skipValidateResponse {
return nil
}
v.mu.Lock()
globalOpenAPI3DocRegistoryMu.Lock()
_, errs := v.validator.ValidateHttpResponse(req, res)
if len(errs) == 0 {
v.mu.Unlock()
globalOpenAPI3DocRegistoryMu.Unlock()
return nil
}
{
// renew validator (workaround)
// ref: https://github.com/k1LoW/runn/issues/882
vv, errrs := validator.NewValidator(v.doc)
if len(errrs) > 0 {
globalOpenAPI3DocRegistoryMu.Unlock()
return errors.Join(errrs...)
}
v.validator = vv
}
v.mu.Unlock()
globalOpenAPI3DocRegistoryMu.Unlock()
var err error
for _, e := range errs {
// nullable type workaround.
Expand Down
4 changes: 2 additions & 2 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ func (op *operator) toOperatorN() *operatorN {
dbg: op.dbg,
}
opn.runNIndex.Store(-1)
opn.dbg.opn = opn // link back to ops
opn.dbg.setOperatorN(opn) // link back to dbg

_ = opn.traverseOperators(op)

Expand Down Expand Up @@ -1397,7 +1397,7 @@ func Load(pathp string, opts ...Option) (*operatorN, error) {
}
opn.runNIndex.Store(-1) // Set index to -1 ( no runN )

opn.dbg.opn = opn // link back to dbg
opn.dbg.setOperatorN(opn) // link back to dbg
if bk.runConcurrent {
opn.concmax = bk.runConcurrentMax
}
Expand Down

0 comments on commit cbdb8b4

Please sign in to comment.