Skip to content

Commit

Permalink
Merge pull request #16 from linyows/millisec
Browse files Browse the repository at this point in the history
Change millisec and Bug fix
  • Loading branch information
linyows authored Aug 17, 2023
2 parents 8875758 + 4c9f00d commit 87bb538
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
- name: Core test
run: go test -v
- name: File-plugin test
run: go test -v
working-directory: ./plugin/file
run: go test -v ./plugin/file
- name: MySQL-plugin test
run: go test -v
working-directory: ./plugin/mysql
run: go test -v ./plugin/mysql
17 changes: 6 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@ run:
env GOOS=$(GOOS) GOARCH=$(GOARCH) go run ./cmd/warp/main.go

test:
go test -v
@go test -v $(shell go list ./... | grep -v integration)

test-all:
go test $(TEST_OPTIONS) -failfast -race -coverpkg=./... -covermode=atomic \
-coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=5m

test-integration:
cd integration && go test -v
integration:
go test -v ./integration

test-mysql-plugin:
cd plugin/mysql && go test -v
test-file-plugin:
cd plugin/file && go test -v
test-all:
go test $(TEST_OPTIONS) -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=5m

mysql-plugin:
env GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -buildmode=plugin -o plugin/mysql.so plugin/mysql/main.go

file-plugin:
env GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -buildmode=plugin -o plugin/file.so plugin/file/main.go

Expand Down
11 changes: 7 additions & 4 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (e Elapse) String() string {
if e < 0 {
return "nil"
}
return fmt.Sprintf("%dsec", e)
return fmt.Sprintf("%d msec", e)
}

func (p *Pipe) Do() {
Expand Down Expand Up @@ -192,8 +192,11 @@ func (p *Pipe) copy(dr Flow, fn Mediator) (written int64, err error) {
go p.afterCommHook(p.removeMailBody(buf[0:nr]), srcToDst)
} else {
// time before email input
if fmt.Sprint(buf[:3]) == fmt.Sprint(codeStartingMailInput) {
p.timeAtDataStarting = time.Now()
list := bytes.Split(buf, []byte(crlf))
for _, v := range list {
if len(v) >= 3 && string(v[:3]) == fmt.Sprint(codeStartingMailInput) {
p.timeAtDataStarting = time.Now()
}
}
// remove buffering ready response
if bytes.Contains(buf, []byte("Ready to start TLS")) || bytes.Contains(buf, []byte("SMTP server ready")) || bytes.Contains(buf, []byte("Start TLS")) {
Expand Down Expand Up @@ -348,5 +351,5 @@ func (p *Pipe) elapse() Elapse {
log.Print("oops, data time is zero")
return -1
}
return Elapse(p.timeAtConnected.Sub(p.timeAtDataStarting).Seconds())
return Elapse(p.timeAtDataStarting.Sub(p.timeAtConnected).Milliseconds())
}
8 changes: 4 additions & 4 deletions pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestElapseString(t *testing.T) {
}{
{
elapse: 2147483647,
expect: "2147483647sec",
expect: "2147483647 msec",
},
{
elapse: -1,
Expand All @@ -175,7 +175,7 @@ func TestElapse(t *testing.T) {
{
start: time.Date(2023, time.August, 16, 14, 48, 0, 0, time.UTC),
stop: time.Date(2023, time.August, 16, 14, 48, 20, 0, time.UTC),
expect: 20,
expect: 20000,
},
{
start: time.Time{},
Expand All @@ -191,8 +191,8 @@ func TestElapse(t *testing.T) {

for _, v := range tests {
p := &Pipe{
timeAtDataStarting: v.start,
timeAtConnected: v.stop,
timeAtConnected: v.start,
timeAtDataStarting: v.stop,
}
got := p.elapse()
if got != v.expect {
Expand Down
2 changes: 1 addition & 1 deletion plugin/file/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestAfterConn(t *testing.T) {
MailTo: []byte("[email protected]"),
Elapse: 20,
}
expect := []byte(`{"type":"conn","occurred_at":"2023-08-16T14:48:00Z","connection_id":"abcdefg","from":"[email protected]","to":"[email protected]","elapse":"20sec"}
expect := []byte(`{"type":"conn","occurred_at":"2023-08-16T14:48:00Z","connection_id":"abcdefg","from":"[email protected]","to":"[email protected]","elapse":"20 msec"}
`)
f.AfterConn(data)
got := buffer.Bytes()
Expand Down

0 comments on commit 87bb538

Please sign in to comment.