Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed-up some tests and fixing some lint reports. #5258

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ jobs:
- name: Build NATS Server
run: go build

store:
name: Store tests
needs: [build-latest, build-supported, lint]
runs-on: ${{ vars.GHA_WORKER_MEDIUM }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Run unit tests
run: |
go test -race -v -run=TestMemStore ./server/... -count=1 -vet=off -timeout=30m -failfast
go test -race -v -run=TestFileStore ./server/... -count=1 -vet=off -timeout=30m -failfast

js-no-cluster:
name: JetStream tests
needs: [build-latest, build-supported, lint]
Expand Down Expand Up @@ -212,8 +230,24 @@ jobs:
- name: Run unit tests
run: go test -race -v -run=TestMQTT ./server/... -count=1 -vet=off -timeout=30m -failfast

msgtrace:
name: MsgTrace tests
needs: [build-latest, build-supported, lint]
runs-on: ${{ vars.GHA_WORKER_MEDIUM }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Run unit tests
run: go test -race -v -run=TestMsgTrace ./server/... -count=1 -vet=off -timeout=30m -failfast

server-pkg-non-js:
name: Non-JetStream/MQTT tests
name: Non-JetStream/MQTT/MsgTrace tests
needs: [build-latest, build-supported, lint]
runs-on: ${{ vars.GHA_WORKER_LARGE }}
steps:
Expand All @@ -226,7 +260,7 @@ jobs:
go-version: stable

- name: Run unit tests
run: go test -race -v -p=1 ./server/... -tags=skip_js_tests,skip_mqtt_tests -count=1 -vet=off -timeout=30m -failfast
run: go test -race -v -p=1 ./server/... -tags=skip_js_tests,skip_store_tests,skip_mqtt_tests,skip_msgtrace_tests -count=1 -vet=off -timeout=30m -failfast
timeout-minutes: 15

non-server-pkg:
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
env: TEST_SUITE=compile
- name: "Run TestNoRace tests"
env: TEST_SUITE=no_race_tests
- name: "Run Store tests"
env: TEST_SUITE=store_tests
- name: "Run JetStream tests"
env: TEST_SUITE=js_tests
- name: "Run JetStream cluster tests (1)"
Expand All @@ -36,7 +38,9 @@ jobs:
env: TEST_SUITE=js_super_cluster_tests
- name: "Run MQTT tests"
env: TEST_SUITE=mqtt_tests
- name: "Run non JetStream/MQTT tests from the server package"
- name: "Run Message Tracing tests"
env: TEST_SUITE=msgtrace_tests
- name: "Run all other tests from the server package"
env: TEST_SUITE=srv_pkg_non_js_tests
- name: "Run all tests from all other packages"
env: TEST_SUITE=non_srv_pkg_tests
Expand Down
2 changes: 1 addition & 1 deletion conf/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (lx *lexer) peek() rune {
// errorf stops all lexing by emitting an error and returning `nil`.
// Note that any value that is a character is escaped if it's a special
// character (new lines, tabs, etc.).
func (lx *lexer) errorf(format string, values ...interface{}) stateFn {
func (lx *lexer) errorf(format string, values ...any) stateFn {
for i, value := range values {
if v, ok := value.(rune); ok {
values[i] = escapeSpecial(v)
Expand Down
44 changes: 22 additions & 22 deletions conf/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ import (
)

type parser struct {
mapping map[string]interface{}
mapping map[string]any
lx *lexer

// The current scoped context, can be array or map
ctx interface{}
ctx any

// stack of contexts, either map or array/slice stack
ctxs []interface{}
ctxs []any

// Keys stack
keys []string
Expand All @@ -58,10 +58,10 @@ type parser struct {
pedantic bool
}

// Parse will return a map of keys to interface{}, although concrete types
// Parse will return a map of keys to any, although concrete types
// underly them. The values supported are string, bool, int64, float64, DateTime.
// Arrays and nested Maps are also supported.
func Parse(data string) (map[string]interface{}, error) {
func Parse(data string) (map[string]any, error) {
p, err := parse(data, "", false)
if err != nil {
return nil, err
Expand All @@ -70,7 +70,7 @@ func Parse(data string) (map[string]interface{}, error) {
}

// ParseFile is a helper to open file, etc. and parse the contents.
func ParseFile(fp string) (map[string]interface{}, error) {
func ParseFile(fp string) (map[string]any, error) {
data, err := os.ReadFile(fp)
if err != nil {
return nil, fmt.Errorf("error opening config file: %v", err)
Expand All @@ -84,7 +84,7 @@ func ParseFile(fp string) (map[string]interface{}, error) {
}

// ParseFileWithChecks is equivalent to ParseFile but runs in pedantic mode.
func ParseFileWithChecks(fp string) (map[string]interface{}, error) {
func ParseFileWithChecks(fp string) (map[string]any, error) {
data, err := os.ReadFile(fp)
if err != nil {
return nil, err
Expand All @@ -100,12 +100,12 @@ func ParseFileWithChecks(fp string) (map[string]interface{}, error) {

type token struct {
item item
value interface{}
value any
usedVariable bool
sourceFile string
}

func (t *token) Value() interface{} {
func (t *token) Value() any {
return t.value
}

Expand All @@ -127,9 +127,9 @@ func (t *token) Position() int {

func parse(data, fp string, pedantic bool) (p *parser, err error) {
p = &parser{
mapping: make(map[string]interface{}),
mapping: make(map[string]any),
lx: lex(data),
ctxs: make([]interface{}, 0, 4),
ctxs: make([]any, 0, 4),
keys: make([]string, 0, 4),
ikeys: make([]item, 0, 4),
fp: filepath.Dir(fp),
Expand Down Expand Up @@ -160,12 +160,12 @@ func (p *parser) next() item {
return p.lx.nextItem()
}

func (p *parser) pushContext(ctx interface{}) {
func (p *parser) pushContext(ctx any) {
p.ctxs = append(p.ctxs, ctx)
p.ctx = ctx
}

func (p *parser) popContext() interface{} {
func (p *parser) popContext() any {
if len(p.ctxs) == 0 {
panic("BUG in parser, context stack empty")
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (p *parser) popItemKey() item {
}

func (p *parser) processItem(it item, fp string) error {
setValue := func(it item, v interface{}) {
setValue := func(it item, v any) {
if p.pedantic {
p.setValue(&token{it, v, false, fp})
} else {
Expand All @@ -226,7 +226,7 @@ func (p *parser) processItem(it item, fp string) error {
p.pushItemKey(it)
}
case itemMapStart:
newCtx := make(map[string]interface{})
newCtx := make(map[string]any)
p.pushContext(newCtx)
case itemMapEnd:
setValue(it, p.popContext())
Expand Down Expand Up @@ -309,7 +309,7 @@ func (p *parser) processItem(it item, fp string) error {
}
setValue(it, dt)
case itemArrayStart:
var array = make([]interface{}, 0)
var array = make([]any, 0)
p.pushContext(array)
case itemArrayEnd:
array := p.ctx
Expand Down Expand Up @@ -342,7 +342,7 @@ func (p *parser) processItem(it item, fp string) error {
}
case itemInclude:
var (
m map[string]interface{}
m map[string]any
err error
)
if p.pedantic {
Expand Down Expand Up @@ -380,7 +380,7 @@ const bcryptPrefix = "2a$"
// ignore array contexts and only process the map contexts..
//
// Returns true for ok if it finds something, similar to map.
func (p *parser) lookupVariable(varReference string) (interface{}, bool, error) {
func (p *parser) lookupVariable(varReference string) (any, bool, error) {
// Do special check to see if it is a raw bcrypt string.
if strings.HasPrefix(varReference, bcryptPrefix) {
return "$" + varReference, true, nil
Expand All @@ -390,7 +390,7 @@ func (p *parser) lookupVariable(varReference string) (interface{}, bool, error)
for i := len(p.ctxs) - 1; i >= 0; i-- {
ctx := p.ctxs[i]
// Process if it is a map context
if m, ok := ctx.(map[string]interface{}); ok {
if m, ok := ctx.(map[string]any); ok {
if v, ok := m[varReference]; ok {
return v, ok, nil
}
Expand All @@ -411,17 +411,17 @@ func (p *parser) lookupVariable(varReference string) (interface{}, bool, error)
return nil, false, nil
}

func (p *parser) setValue(val interface{}) {
func (p *parser) setValue(val any) {
// Test to see if we are on an array or a map

// Array processing
if ctx, ok := p.ctx.([]interface{}); ok {
if ctx, ok := p.ctx.([]any); ok {
p.ctx = append(ctx, val)
p.ctxs[len(p.ctxs)-1] = p.ctx
}

// Map processing
if ctx, ok := p.ctx.(map[string]interface{}); ok {
if ctx, ok := p.ctx.(map[string]any); ok {
key := p.popKey()

if p.pedantic {
Expand Down
Loading