Skip to content

Commit

Permalink
ts field
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Feb 11, 2024
1 parent cb8e0c3 commit 534fe04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand All @@ -22,8 +21,8 @@ func TestGenerateRandomData(t *testing.T) {
go generateRandomData(true, 100, ch, ctx)

i := 0
var firstM time.Time
var lastM time.Time
var firstM int64
var lastM int64
var msg Message
for {
msg = <-ch
Expand All @@ -39,7 +38,7 @@ func TestGenerateRandomData(t *testing.T) {
}

assert.Equal(t, msg.IsJson, true)
assert.Greater(t, lastM.Sub(firstM).Milliseconds(), int64(90))
assert.Greater(t, lastM-firstM, int64(90))
cancel()
}
func TestGenerateRandomData2(t *testing.T) {
Expand All @@ -49,8 +48,8 @@ func TestGenerateRandomData2(t *testing.T) {
go generateRandomData(false, 100, ch, ctx)

i := 0
var firstM time.Time
var lastM time.Time
var firstM int64
var lastM int64
var msg Message
for {
msg = <-ch
Expand All @@ -66,6 +65,6 @@ func TestGenerateRandomData2(t *testing.T) {
}

assert.Equal(t, msg.IsJson, false)
assert.Greater(t, lastM.Sub(firstM).Milliseconds(), int64(90))
assert.Greater(t, lastM-firstM, int64(90))
cancel()
}
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Message struct {
Content string `json:"content"`
JsonContent json.RawMessage `json:"json_content"`
IsJson bool `json:"is_json"`
Ts time.Time `json:"ts"`
Ts int64 `json:"ts"`
Origin *MessageOrigin `json:"origin"`
}

Expand Down
2 changes: 1 addition & 1 deletion producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func produce(ch chan Message, line string, mt LogType, mo *MessageOrigin) {
IsJson: validJson == nil,
BaseMessage: BaseMessage{MessageType: "log"},
Origin: mo,
Ts: time.Now(),
Ts: time.Now().UnixMilli(),
}
}

Expand Down

0 comments on commit 534fe04

Please sign in to comment.