Skip to content

Commit

Permalink
all: fix errors reported by 'go vet'
Browse files Browse the repository at this point in the history
Also enable this check so that we don't run into the same problem
again in the future.
  • Loading branch information
kevinburkesegment committed Feb 27, 2024
1 parent f41aec0 commit 6649bb0
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 37 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Test
run: |
make test
make fmtchk vet test
- name: build
run: |
Expand Down Expand Up @@ -116,5 +116,3 @@ jobs:
--push \
.
- run: echo "GHCR PUBLISH SUCCESSFUL"


1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,3 @@ test:
.PHONY: bench
bench:
$Qgo test $(GOTESTFLAGS) -bench .

2 changes: 1 addition & 1 deletion pkg/cmd/ctlstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func newReflector(cliCfg reflectorCliConfig, isSupervisor bool, i int) (*reflect
events.Log("DEPRECATION NOTICE: use --disable-ecs-behavior instead of --disable to control this ledger monitor behavior")
}
id := fmt.Sprintf("%s-%d", path.Base(cliCfg.LDBPath), i)
l := events.NewLogger(events.DefaultHandler).With(events.Args{{"id", id}})
l := events.NewLogger(events.DefaultHandler).With(events.Args{{Name: "id", Value: id}})
l.EnableDebug = cliCfg.Debug
return reflectorpkg.ReflectorFromConfig(reflectorpkg.ReflectorConfig{
LDBPath: cliCfg.LDBPath,
Expand Down
8 changes: 6 additions & 2 deletions pkg/event/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ func TestChangelog(t *testing.T) {
rotateAfter: test.rotateAfter,
rotateAfterBytes: test.rotateAfterBytes,
}
var writeErr error
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
err := flw.writeN(ctx, test.numEvents)
if err != nil {
t.Fatal(err)
writeErr = err
}
}()
defer wg.Wait()
for i := 0; i < test.numEvents; i++ {
event, err := cl.next(ctx)
if err != nil {
Expand All @@ -182,6 +182,10 @@ func TestChangelog(t *testing.T) {
if test.mustRotateN > 0 {
require.EqualValues(t, test.mustRotateN, atomic.LoadInt64(&flw.rotations))
}
wg.Wait()
if writeErr != nil {
t.Fatal(writeErr)
}
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/executive/db_executive.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (e *dbExecutive) CreateTable(familyName string, tableName string, fieldName

err = tbl.Validate()
if err != nil {
return &errs.BadRequestError{err.Error()}
return &errs.BadRequestError{Err: err.Error()}
}

ddl, err := tbl.AsCreateTableDDL()
Expand Down
7 changes: 4 additions & 3 deletions pkg/executive/dml_ledger_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestDMLLogWriterAdd(t *testing.T) {

for i, testCase := range suite {
testName := fmt.Sprintf("[%d] %s", i, testCase.desc)
statements := testCase.statements
t.Run(testName, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand All @@ -42,7 +43,7 @@ func TestDMLLogWriterAdd(t *testing.T) {
defer w.Close()

seqs := []schema.DMLSequence{}
for _, stString := range testCase.statements {
for _, stString := range statements {
seq, err := w.Add(ctx, stString)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestDMLLogWriterAdd(t *testing.T) {

i := 0
for rows.Next() {
if i+1 > len(testCase.statements) {
if i+1 > len(statements) {
t.Errorf("Scanned more statements than expected")
break
}
Expand All @@ -98,7 +99,7 @@ func TestDMLLogWriterAdd(t *testing.T) {
t.Errorf("Expected %v, got %v", want, got)
}

if want, got := testCase.statements[i], rowStmt; want != got {
if want, got := statements[i], rowStmt; want != got {
t.Errorf("Expected %v, got %v", want, got)
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/reflector/reflector_ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ func (r *ReflectorCtl) lifecycle(appCtx context.Context) {
for {
select {
case <-appCtx.Done():
// the application is quitting
// the application is quitting - cancel the reflector
events.Log("reflectorCtl stopping due to context err=%v", appCtx.Err())
if cancel != nil {
cancel()
}
return
case msg := <-r.messages:
// another goroutine has asked for the reflector to either
// be started or stopped.
switch msg.desired {
case true:
case true: // start the reflector
if !running {
ctx, cancel = context.WithCancel(appCtx)
wg.Add(1)
Expand All @@ -155,7 +158,7 @@ func (r *ReflectorCtl) lifecycle(appCtx context.Context) {
running = true
}
msg.sendErr(appCtx, nil)
case false:
case false: // stop the reflector
if running {
cancel()
done := make(chan struct{})
Expand Down
5 changes: 3 additions & 2 deletions pkg/reflector/reflector_ctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ func TestReflectorCtl(t *testing.T) {
// context root.
func TestReflectorCtlContext(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
ctx2, _ := context.WithCancel(ctx)
ctx2, cancel2 := context.WithCancel(ctx)
defer cancel2()
cancel()
select {
case <-ctx2.Done():
default:
t.Fatal("context should have been canceled")
t.Fatal("child context should have been canceled")
}
}
5 changes: 5 additions & 0 deletions pkg/reflector/shovel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (s *shovel) Start(ctx context.Context) error {
safeCancel()
var sctx context.Context
sctx, cancel = context.WithTimeout(ctx, s.pollTimeout)
safeCancel = func() {
if cancel != nil {
cancel()
}
}

stats.Incr("shovel.loop_enter")
s.logger().Debug("shovel polling...")
Expand Down
42 changes: 21 additions & 21 deletions pkg/sqlgen/sqlgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func TestMetaTableAsCreateTableDDL(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTInteger},
{schema.FieldName{Name: "field3"}, schema.FTDecimal},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTInteger},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTDecimal},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand Down Expand Up @@ -176,10 +176,10 @@ func TestMetaTableUpsertDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{schema.FieldName{Name: "field4"}, schema.FTByteString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
{Name: schema.FieldName{Name: "field4"}, FieldType: schema.FTByteString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand All @@ -200,9 +200,9 @@ func TestMetaTableUpsertDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand All @@ -222,9 +222,9 @@ func TestMetaTableUpsertDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand Down Expand Up @@ -261,9 +261,9 @@ func TestMetaTableDeleteDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTByteString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTByteString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand All @@ -285,8 +285,8 @@ func TestMetaTableDeleteDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand All @@ -313,8 +313,8 @@ func TestMetaTableClearTableDDL(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTByteString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTByteString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand All @@ -334,7 +334,7 @@ func TestMetaTableDropTableDDL(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand Down

0 comments on commit 6649bb0

Please sign in to comment.