Skip to content

Commit e335d3d

Browse files
authored
Merge pull request #527 from quickfixgo/fix-ci
Upgrades mongo driver, resolves broken ci config, adds dynamic session fix
2 parents 7b665fe + afa1631 commit e335d3d

File tree

16 files changed

+214
-96
lines changed

16 files changed

+214
-96
lines changed
File renamed without changes.

.devcontainer/devcontainer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
2-
"name": "Go & Mongo DB",
2+
"name": "Quickfix/Go Development",
33
"dockerComposeFile": "docker-compose.yml",
44
"service": "app",
55
"workspaceFolder": "/workspace",
6+
"shutdownAction": "stopCompose",
67
"runArgs": [
78
"--cap-add=SYS_PTRACE",
89
"--security-opt",
910
"seccomp=unconfined"
1011
],
12+
"features": {
13+
"ruby": "latest"
14+
},
1115
"customizations": {
1216
"vscode": {
1317
"settings": {

.devcontainer/docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ services:
44
app:
55
build:
66
context: .
7-
dockerfile: Dockerfile
7+
dockerfile: Dockerfile.dev
88
volumes:
99
- ..:/workspace:cached
10-
10+
- /var/run/docker.sock:/var/run/docker.sock
1111
# Overrides default command so things don't shut down after the process ends.
1212
command: sleep infinity
1313

@@ -25,7 +25,8 @@ services:
2525
restart: unless-stopped
2626
volumes:
2727
- mongodb-data:/data/db
28-
28+
ports:
29+
- 27017:27017
2930
# Uncomment to change startup options
3031
# environment:
3132
# MONGO_INITDB_ROOT_USERNAME: root

.github/workflows/ci.yaml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,31 @@ jobs:
4747
matrix:
4848
go: [1.18]
4949
fix-version:
50-
- FIX_TEST=
51-
- FIX_TEST=fix40
52-
- FIX_TEST=fix41
53-
- FIX_TEST=fix42
54-
- FIX_TEST=fix43
55-
- FIX_TEST=fix44
56-
- FIX_TEST=fix50
57-
- FIX_TEST=fix50sp1
58-
- FIX_TEST=fix50sp2
50+
-
51+
- fix40
52+
- fix41
53+
- fix42
54+
- fix43
55+
- fix44
56+
- fix50
57+
- fix50sp1
58+
- fix50sp2
5959
steps:
6060
- name: Setup
6161
uses: actions/setup-go@v2
6262
with:
6363
go-version: ${{ matrix.go }}
6464
- name: Check out source
6565
uses: actions/checkout@v2
66-
- name: Run Mongo
67-
run: docker run -d -p 27017:27017 mongo
66+
- name: Start MongoDB
67+
uses: supercharge/[email protected]
68+
- name: Install ruby
69+
uses: ruby/setup-ruby@v1
70+
with:
71+
ruby-version: '3.0'
6872
- name: Test
6973
env:
70-
GO111MODULE: "on"
71-
MONGODB_TEST_CXN: "localhost"
72-
run: make generate; if [ -z "$FIX_TEST" ]; then make build; make; else make build_accept; make $FIX_TEST; fi
74+
GO111MODULE: on
75+
MONGODB_TEST_CXN: mongodb://localhost:27017
76+
FIX_TEST: ${{ matrix.fix-version }}
77+
run: if [ -z $FIX_TEST ]; then make build-src && make test-ci; else make generate-ci && make build && make $FIX_TEST; fi

Makefile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ clean:
2727
rm -rf gen
2828

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

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

4948
test:
50-
MONGODB_TEST_CXN=localhost go test -v -cover . ./datadictionary ./internal
49+
MONGODB_TEST_CXN=mongodb://db:27017 go test -v -cover . ./datadictionary ./internal
5150

52-
_build_all:
51+
build-src:
5352
go build -v `go list ./...`
5453

55-
build_accept:
56-
cd _test; go build -o echo_server
54+
build-test-srv:
55+
cd _test; go build -o echo_server ./test-server/
5756

58-
build: _build_all build_accept
57+
build: build-src build-test-srv
58+
59+
test-ci:
60+
go test -v -cover . ./datadictionary ./internal
61+
62+
generate-ci: clean
63+
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;
5964

6065
fix40:
6166
cd _test; ./runat.sh $@.cfg 5001 "definitions/server/$@/*.def"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ To run acceptance tests,
100100
make generate
101101

102102
# build acceptance test rig
103-
make build_accept
103+
make build-test-srv
104104

105105
# run acceptance tests
106106
make accept

_test/echo_server.go renamed to _test/test-server/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package main
22

33
import (
4+
"bytes"
45
"fmt"
56
"io/ioutil"
67
"log"
78
"os"
89
"os/signal"
910

1011
"github.com/quickfixgo/quickfix"
11-
"github.com/quickfixgo/quickfix/gen/field"
12-
"github.com/quickfixgo/quickfix/gen/tag"
12+
field "github.com/quickfixgo/quickfix/gen/field"
13+
tag "github.com/quickfixgo/quickfix/gen/tag"
1314
)
1415

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

5960
sessionOrderID := sessionID.String() + orderID.String()
60-
if possResend.FIXBoolean {
61+
62+
if bytes.Equal(possResend.Write(), []byte("Y")) {
6163
if e.OrderIds[sessionOrderID] {
6264
return nil
6365
}
@@ -67,7 +69,7 @@ func (e *EchoApplication) processMsg(msg *quickfix.Message, sessionID quickfix.S
6769
}
6870

6971
reply := copyMessage(msg)
70-
if possResend.FIXBoolean {
72+
if bytes.Equal(possResend.Write(), []byte("Y")) {
7173
reply.Header.Set(possResend)
7274
}
7375

@@ -109,6 +111,7 @@ func main() {
109111
router.AddRoute(quickfix.ApplVerIDFIX50SP1, "d", app.processMsg)
110112
router.AddRoute(quickfix.ApplVerIDFIX50SP2, "d", app.processMsg)
111113

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

142-
interrupt := make(chan os.Signal)
143-
signal.Notify(interrupt)
144-
<-interrupt
145+
c := make(chan os.Signal, 1)
146+
signal.Notify(c, os.Interrupt)
147+
<-c
148+
fmt.Println("stopping test server")
145149

146150
acceptor.Stop()
147151
}

acceptor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (a *Acceptor) handleConnection(netConn net.Conn) {
290290
}
291291

292292
localConnectionPort := netConn.LocalAddr().(*net.TCPAddr).Port
293-
if expectedPort, ok := a.sessionHostPort[sessID]; !ok || expectedPort != localConnectionPort {
293+
if expectedPort, ok := a.sessionHostPort[sessID]; ok && expectedPort != localConnectionPort {
294294
a.globalLog.OnEventf("Session %v not found for incoming message: %s", sessID, msgBytes)
295295
return
296296
}

cmd/generate-fix/generate-fix.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,26 @@ func main() {
122122
usage()
123123
}
124124

125-
specs := make([]*datadictionary.DataDictionary, flag.NArg())
126-
for i, dataDictPath := range flag.Args() {
127-
var err error
128-
specs[i], err = datadictionary.Parse(dataDictPath)
125+
126+
args := flag.Args()
127+
if len(args) == 1 {
128+
dictpath := args[0]
129+
if strings.Contains(dictpath, "FIX50SP1") {
130+
args = append(args, strings.Replace(dictpath, "FIX50SP1", "FIXT11", -1))
131+
} else if strings.Contains(dictpath, "FIX50SP2") {
132+
args = append(args, strings.Replace(dictpath, "FIX50SP2", "FIXT11", -1))
133+
} else if strings.Contains(dictpath, "FIX50") {
134+
args = append(args, strings.Replace(dictpath, "FIX50", "FIXT11", -1))
135+
}
136+
}
137+
specs := []*datadictionary.DataDictionary{}
138+
139+
for _, dataDictPath := range args {
140+
spec, err := datadictionary.Parse(dataDictPath)
129141
if err != nil {
130142
log.Fatalf("Error Parsing %v: %v", dataDictPath, err)
131143
}
144+
specs = append(specs, spec)
132145
}
133146

134147
internal.BuildGlobalFieldTypes(specs)

cmd/generate-fix/internal/template_helpers.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ func checkIfDecimalImportRequiredForFields(fTypes []*datadictionary.FieldType) (
2222
return
2323
}
2424

25+
func checkIfTimeImportRequiredForFields(fTypes []*datadictionary.FieldType) (ok bool, err error) {
26+
var t string
27+
for _, fType := range fTypes {
28+
t, err = quickfixType(fType)
29+
if err != nil {
30+
return
31+
}
32+
33+
var vt string
34+
if vt, err = quickfixValueType(t); err != nil {
35+
return
36+
}
37+
38+
if vt == "time.Time" {
39+
return true, nil
40+
}
41+
}
42+
43+
return
44+
}
45+
2546
func checkFieldDecimalRequired(f *datadictionary.FieldDef) (required bool, err error) {
2647
var globalType *datadictionary.FieldType
2748
if globalType, err = getGlobalFieldType(f); err != nil {

0 commit comments

Comments
 (0)