diff --git a/Makefile b/Makefile index 71ab3dd82..b354870a9 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,9 @@ test: ## runs integration tests that require local applications such as MongoDB go test -tags integration -race ./... bench: ## runs benchmark tests - go test -tags bench -benchmem -bench=. ./test/bench -memprofile=mem.prof -cpuprofile=cpu.prof | tee output.txt + mkfifo pipe + tee output.txt < pipe & + go test -tags bench -benchmem -bench=. ./test/bench -memprofile=mem.prof -cpuprofile=cpu.prof > pipe docker: ## builds docker images with the current version and latest tag docker buildx build --push --platform linux/amd64,linux/arm64,linux/386 -t yorkieteam/yorkie:$(YORKIE_VERSION) -t yorkieteam/yorkie:latest . diff --git a/pkg/document/crdt/rht_test.go b/pkg/document/crdt/rht_test.go index c422c4473..39d20da0f 100644 --- a/pkg/document/crdt/rht_test.go +++ b/pkg/document/crdt/rht_test.go @@ -12,7 +12,7 @@ func TestMarshal(t *testing.T) { value1 := "world\"\f\b" key2 := "hi" value2 := `test\r` - expected := `{"hello\\\\\\t":"world\\"\\f\\b","hi":"test\\r"}` + expected := `{"hello\\\\\\t":"world\"\f\b","hi":"test\\r"}` rht := NewRHT() rht.Set(key1, value1, nil) diff --git a/pkg/document/crdt/strings.go b/pkg/document/crdt/strings.go index ca9fb251f..707677a1f 100644 --- a/pkg/document/crdt/strings.go +++ b/pkg/document/crdt/strings.go @@ -36,31 +36,24 @@ func EscapeString(s string) string { buf.WriteByte('\\') buf.WriteByte('\\') case '"': - buf.WriteByte('\\') buf.WriteByte('\\') buf.WriteByte('"') case '\n': - buf.WriteByte('\\') buf.WriteByte('\\') buf.WriteByte('n') case '\f': - buf.WriteByte('\\') buf.WriteByte('\\') buf.WriteByte('f') case '\b': - buf.WriteByte('\\') buf.WriteByte('\\') buf.WriteByte('b') case '\r': - buf.WriteByte('\\') buf.WriteByte('\\') buf.WriteByte('r') case '\t': - buf.WriteByte('\\') buf.WriteByte('\\') buf.WriteByte('t') default: - buf.WriteByte('\\') buf.WriteByte('\\') buf.WriteByte('u') buf.WriteByte('0') diff --git a/pkg/document/crdt/strings_test.go b/pkg/document/crdt/strings_test.go index 395ac2cff..2e11b4d55 100644 --- a/pkg/document/crdt/strings_test.go +++ b/pkg/document/crdt/strings_test.go @@ -30,30 +30,16 @@ func TestEscapeString(t *testing.T) { assert.Equal(t, expected, actual) }) - t.Run("escape string with doublequote", func(t *testing.T) { - str := `hello world"` - expected := `hello world\\"` + t.Run("escape string with backslash, doublequote and control characters", func(t *testing.T) { + str := "hello world\"\\\n\f\b\r\t" + expected := `hello world\"\\\n\f\b\r\t` actual := EscapeString(str) assert.Equal(t, expected, actual) }) - t.Run("escape string with raw control character", func(t *testing.T) { - str := "hello world\n" - expected := `hello world\\n` - actual := EscapeString(str) - assert.Equal(t, expected, actual) - }) - - t.Run("escape string with escaped control character", func(t *testing.T) { - str := `hello world\n` - expected := `hello world\\n` - actual := EscapeString(str) - assert.Equal(t, expected, actual) - }) - - t.Run("escape string with raw unicode character", func(t *testing.T) { - str := "hello world\u1234" - expected := "hello world\u1234" + t.Run("escape string with unicode characters", func(t *testing.T) { + str := "hello world\u1234\u6645" + expected := "hello world\u1234\u6645" actual := EscapeString(str) assert.Equal(t, expected, actual) }) diff --git a/pkg/document/document_test.go b/pkg/document/document_test.go index 4158b05c8..d5d7dd460 100644 --- a/pkg/document/document_test.go +++ b/pkg/document/document_test.go @@ -336,7 +336,7 @@ func TestDocument(t *testing.T) { assert.Equal( t, `[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hel"][1:2:00:3 {"b":"1","i":"1"} "lo"]`+ - `[5:1:00:0 {"list":"true"} "\\n"][4:1:00:0 {} " Yorkie"]{1:2:00:5 {} " world"}`, + `[5:1:00:0 {"list":"true"} "\n"][4:1:00:0 {} " Yorkie"]{1:2:00:5 {} " world"}`, text.StructureAsString(), ) return nil @@ -345,7 +345,7 @@ func TestDocument(t *testing.T) { assert.Equal( t, `{"k1":[{"attrs":{"b":"1"},"val":"Hel"},{"attrs":{"b":"1","i":"1"},"val":"lo"},`+ - `{"attrs":{"list":"true"},"val":"\\n"},{"val":" Yorkie"}]}`, + `{"attrs":{"list":"true"},"val":"\n"},{"val":" Yorkie"}]}`, doc.Marshal(), ) }) diff --git a/test/bench/document_bench_test.go b/test/bench/document_bench_test.go index c84be5f2c..20dae0af1 100644 --- a/test/bench/document_bench_test.go +++ b/test/bench/document_bench_test.go @@ -317,7 +317,7 @@ func BenchmarkDocument(b *testing.B) { text.Edit(5, 5, "\n", map[string]string{"list": "true"}) assert.Equal( b, - `[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hel"][1:2:00:3 {"b":"1","i":"1"} "lo"][5:1:00:0 {"list":"true"} "\\n"][4:1:00:0 {} " Yorkie"]{1:2:00:5 {} " world"}`, + `[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hel"][1:2:00:3 {"b":"1","i":"1"} "lo"][5:1:00:0 {"list":"true"} "\n"][4:1:00:0 {} " Yorkie"]{1:2:00:5 {} " world"}`, text.StructureAsString(), ) return nil @@ -325,7 +325,7 @@ func BenchmarkDocument(b *testing.B) { assert.NoError(b, err) assert.Equal( b, - `{"k1":[{"attrs":{"b":"1"},"val":"Hel"},{"attrs":{"b":"1","i":"1"},"val":"lo"},{"attrs":{"list":"true"},"val":"\\n"},{"val":" Yorkie"}]}`, + `{"k1":[{"attrs":{"b":"1"},"val":"Hel"},{"attrs":{"b":"1","i":"1"},"val":"lo"},{"attrs":{"list":"true"},"val":"\n"},{"val":" Yorkie"}]}`, doc.Marshal(), ) }