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

Upgrades mongo driver, resolves broken ci config, adds dynamic session fix #527

Merged
merged 1 commit into from
Dec 7, 2022
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
File renamed without changes.
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "Go & Mongo DB",
"name": "Quickfix/Go Development",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
"features": {
"ruby": "latest"
},
"customizations": {
"vscode": {
"settings": {
Expand Down
7 changes: 4 additions & 3 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ services:
app:
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
volumes:
- ..:/workspace:cached

- /var/run/docker.sock:/var/run/docker.sock
# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

Expand All @@ -25,7 +25,8 @@ services:
restart: unless-stopped
volumes:
- mongodb-data:/data/db

ports:
- 27017:27017
# Uncomment to change startup options
# environment:
# MONGO_INITDB_ROOT_USERNAME: root
Expand Down
33 changes: 19 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,31 @@ jobs:
matrix:
go: [1.18]
fix-version:
- FIX_TEST=
- FIX_TEST=fix40
- FIX_TEST=fix41
- FIX_TEST=fix42
- FIX_TEST=fix43
- FIX_TEST=fix44
- FIX_TEST=fix50
- FIX_TEST=fix50sp1
- FIX_TEST=fix50sp2
-
- fix40
- fix41
- fix42
- fix43
- fix44
- fix50
- fix50sp1
- fix50sp2
steps:
- name: Setup
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Check out source
uses: actions/checkout@v2
- name: Run Mongo
run: docker run -d -p 27017:27017 mongo
- name: Start MongoDB
uses: supercharge/[email protected]
- name: Install ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
- name: Test
env:
GO111MODULE: "on"
MONGODB_TEST_CXN: "localhost"
run: make generate; if [ -z "$FIX_TEST" ]; then make build; make; else make build_accept; make $FIX_TEST; fi
GO111MODULE: on
MONGODB_TEST_CXN: mongodb://localhost:27017
FIX_TEST: ${{ matrix.fix-version }}
run: if [ -z $FIX_TEST ]; then make build-src && make test-ci; else make generate-ci && make build && make $FIX_TEST; fi
19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ clean:
rm -rf gen

generate: clean
mkdir -p gen; cd gen; go run ../cmd/generate-fix/generate-fix.go ../spec/*.xml
go get -u all
mkdir -p gen; cd gen; go run ../cmd/generate-fix/generate-fix.go -pkg-root=github.com/quickfixgo/quickfix/gen ../spec/*.xml

generate-dist:
cd ..; go run quickfix/cmd/generate-fix/generate-fix.go quickfix/spec/*.xml
Expand All @@ -47,15 +46,21 @@ vet:
go vet `go list ./... | grep -v quickfix/gen`

test:
MONGODB_TEST_CXN=localhost go test -v -cover . ./datadictionary ./internal
MONGODB_TEST_CXN=mongodb://db:27017 go test -v -cover . ./datadictionary ./internal

_build_all:
build-src:
go build -v `go list ./...`

build_accept:
cd _test; go build -o echo_server
build-test-srv:
cd _test; go build -o echo_server ./test-server/

build: _build_all build_accept
build: build-src build-test-srv

test-ci:
go test -v -cover . ./datadictionary ./internal

generate-ci: clean
mkdir -p gen; cd gen; go run ../cmd/generate-fix/generate-fix.go -pkg-root=github.com/quickfixgo/quickfix/gen ../spec/$(shell echo $(FIX_TEST) | tr '[:lower:]' '[:upper:]').xml;

fix40:
cd _test; ./runat.sh [email protected] 5001 "definitions/server/$@/*.def"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ To run acceptance tests,
make generate

# build acceptance test rig
make build_accept
make build-test-srv

# run acceptance tests
make accept
Expand Down
18 changes: 11 additions & 7 deletions _test/echo_server.go → _test/test-server/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package main

import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"

"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/gen/field"
"github.com/quickfixgo/quickfix/gen/tag"
field "github.com/quickfixgo/quickfix/gen/field"
tag "github.com/quickfixgo/quickfix/gen/tag"
)

var router *quickfix.MessageRouter = quickfix.NewMessageRouter()
Expand Down Expand Up @@ -57,7 +58,8 @@ func (e *EchoApplication) processMsg(msg *quickfix.Message, sessionID quickfix.S
}

sessionOrderID := sessionID.String() + orderID.String()
if possResend.FIXBoolean {

if bytes.Equal(possResend.Write(), []byte("Y")) {
if e.OrderIds[sessionOrderID] {
return nil
}
Expand All @@ -67,7 +69,7 @@ func (e *EchoApplication) processMsg(msg *quickfix.Message, sessionID quickfix.S
}

reply := copyMessage(msg)
if possResend.FIXBoolean {
if bytes.Equal(possResend.Write(), []byte("Y")) {
reply.Header.Set(possResend)
}

Expand Down Expand Up @@ -109,6 +111,7 @@ func main() {
router.AddRoute(quickfix.ApplVerIDFIX50SP1, "d", app.processMsg)
router.AddRoute(quickfix.ApplVerIDFIX50SP2, "d", app.processMsg)

fmt.Println("starting test server")
cfg, err := os.Open(os.Args[1])
if err != nil {
fmt.Printf("Error opening %v, %v\n", os.Args[1], err)
Expand Down Expand Up @@ -139,9 +142,10 @@ func main() {
return
}

interrupt := make(chan os.Signal)
signal.Notify(interrupt)
<-interrupt
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
fmt.Println("stopping test server")

acceptor.Stop()
}
2 changes: 1 addition & 1 deletion acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (a *Acceptor) handleConnection(netConn net.Conn) {
}

localConnectionPort := netConn.LocalAddr().(*net.TCPAddr).Port
if expectedPort, ok := a.sessionHostPort[sessID]; !ok || expectedPort != localConnectionPort {
if expectedPort, ok := a.sessionHostPort[sessID]; ok && expectedPort != localConnectionPort {
Copy link

@mikhailovavexmocom mikhailovavexmocom Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for reference within #522)

a.globalLog.OnEventf("Session %v not found for incoming message: %s", sessID, msgBytes)
return
}
Expand Down
21 changes: 17 additions & 4 deletions cmd/generate-fix/generate-fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,26 @@ func main() {
usage()
}

specs := make([]*datadictionary.DataDictionary, flag.NArg())
for i, dataDictPath := range flag.Args() {
var err error
specs[i], err = datadictionary.Parse(dataDictPath)

args := flag.Args()
if len(args) == 1 {
dictpath := args[0]
if strings.Contains(dictpath, "FIX50SP1") {
args = append(args, strings.Replace(dictpath, "FIX50SP1", "FIXT11", -1))
} else if strings.Contains(dictpath, "FIX50SP2") {
args = append(args, strings.Replace(dictpath, "FIX50SP2", "FIXT11", -1))
} else if strings.Contains(dictpath, "FIX50") {
args = append(args, strings.Replace(dictpath, "FIX50", "FIXT11", -1))
}
}
specs := []*datadictionary.DataDictionary{}

for _, dataDictPath := range args {
spec, err := datadictionary.Parse(dataDictPath)
if err != nil {
log.Fatalf("Error Parsing %v: %v", dataDictPath, err)
}
specs = append(specs, spec)
}

internal.BuildGlobalFieldTypes(specs)
Expand Down
21 changes: 21 additions & 0 deletions cmd/generate-fix/internal/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ func checkIfDecimalImportRequiredForFields(fTypes []*datadictionary.FieldType) (
return
}

func checkIfTimeImportRequiredForFields(fTypes []*datadictionary.FieldType) (ok bool, err error) {
var t string
for _, fType := range fTypes {
t, err = quickfixType(fType)
if err != nil {
return
}

var vt string
if vt, err = quickfixValueType(t); err != nil {
return
}

if vt == "time.Time" {
return true, nil
}
}

return
}

func checkFieldDecimalRequired(f *datadictionary.FieldDef) (required bool, err error) {
var globalType *datadictionary.FieldType
if globalType, err = getGlobalFieldType(f); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/generate-fix/internal/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
"getGlobalFieldType": getGlobalFieldType,
"collectExtraImports": collectExtraImports,
"checkIfDecimalImportRequiredForFields": checkIfDecimalImportRequiredForFields,
"checkIfTimeImportRequiredForFields": checkIfTimeImportRequiredForFields,
"checkIfEnumImportRequired": checkIfEnumImportRequired,
}

Expand Down Expand Up @@ -312,7 +313,7 @@ import(
"{{ importRootPath }}/enum"
"{{ importRootPath }}/tag"
{{ if checkIfDecimalImportRequiredForFields . }} "github.com/shopspring/decimal" {{ end }}
"time"
{{ if checkIfTimeImportRequiredForFields . }} "time" {{ end }}
)

{{ range . }}
Expand Down
2 changes: 1 addition & 1 deletion config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Directory to store sequence number and message files. Only used with FileStoreF

MongoStoreConnection

The MongoDB connection URL to use (see https://godoc.org/github.com/globalsign/mgo#Dial for the URL Format). Only used with MongoStoreFactory.
The MongoDB connection URL to use (see https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more info). Only used with MongoStoreFactory.

MongoStoreDatabase

Expand Down
24 changes: 19 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@ go 1.18

require (
github.com/armon/go-proxyproto v0.0.0-20210323213023-7e956b284f0a
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/mattn/go-sqlite3 v1.14.14
github.com/mattn/go-sqlite3 v1.14.16
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.0.0-20220708220712-1185a9018129
github.com/stretchr/testify v1.8.1
go.mongodb.org/mongo-driver v1.11.0
golang.org/x/net v0.2.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.5.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading