You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/10/05 19:58:12 UTC

[GitHub] [incubator-kvrocks] tisonkun commented on a diff in pull request #935: Move TCL test unit/slowlog to Go case

tisonkun commented on code in PR #935:
URL: https://github.com/apache/incubator-kvrocks/pull/935#discussion_r985334944


##########
tests/gocase/unit/slowlog/slowlog_test.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package slowlog
+
+import (
+	"context"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/go-redis/redis/v9"
+	"github.com/stretchr/testify/require"
+)
+
+func TestSlowlog(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{})
+	defer srv.Close()
+	ctx := context.Background()
+	rdb := srv.NewClient()
+	defer func() { require.NoError(t, rdb.Close()) }()
+
+	t.Run("SLOWLOG - check that it starts with an empty log", func(t *testing.T) {
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - only logs commands taking more time than specified", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 100000).Err())
+		require.NoError(t, rdb.Ping(ctx).Err())
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - max entries is correctly handled", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 0).Err())
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-max-len", 10).Err())
+		for i := 0; i < 100; i++ {
+			require.NoError(t, rdb.Ping(ctx).Err())
+		}
+		require.EqualValues(t, 10, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - GET optional argument to limit output len works", func(t *testing.T) {
+		require.EqualValues(t, 5, reflect.ValueOf(rdb.Do(ctx, "slowlog", "get", 5).Val()).Len())

Review Comment:
   use `rdb.SlowLogGet` and assert the return `[]SlowLog` array.



##########
tests/gocase/unit/slowlog/slowlog_test.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package slowlog
+
+import (
+	"context"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/go-redis/redis/v9"
+	"github.com/stretchr/testify/require"
+)
+
+func TestSlowlog(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{})
+	defer srv.Close()
+	ctx := context.Background()
+	rdb := srv.NewClient()
+	defer func() { require.NoError(t, rdb.Close()) }()
+
+	t.Run("SLOWLOG - check that it starts with an empty log", func(t *testing.T) {
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - only logs commands taking more time than specified", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 100000).Err())

Review Comment:
   use `rdb.ConfigSet`



##########
tests/gocase/unit/slowlog/slowlog_test.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package slowlog
+
+import (
+	"context"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/go-redis/redis/v9"
+	"github.com/stretchr/testify/require"
+)
+
+func TestSlowlog(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{})
+	defer srv.Close()
+	ctx := context.Background()
+	rdb := srv.NewClient()
+	defer func() { require.NoError(t, rdb.Close()) }()
+
+	t.Run("SLOWLOG - check that it starts with an empty log", func(t *testing.T) {
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - only logs commands taking more time than specified", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 100000).Err())
+		require.NoError(t, rdb.Ping(ctx).Err())
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - max entries is correctly handled", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 0).Err())
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-max-len", 10).Err())
+		for i := 0; i < 100; i++ {
+			require.NoError(t, rdb.Ping(ctx).Err())
+		}
+		require.EqualValues(t, 10, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - GET optional argument to limit output len works", func(t *testing.T) {
+		require.EqualValues(t, 5, reflect.ValueOf(rdb.Do(ctx, "slowlog", "get", 5).Val()).Len())
+	})
+
+	t.Run("SLOWLOG - RESET subcommand works", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 100000).Err())
+		require.NoError(t, rdb.Do(ctx, "slowlog", "reset").Err())
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - logged entry sanity check", func(t *testing.T) {

Review Comment:
   use `rdb.SlowLogGet` and assert the return `[]SlowLog` array.



##########
tests/gocase/unit/slowlog/slowlog_test.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package slowlog
+
+import (
+	"context"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/go-redis/redis/v9"
+	"github.com/stretchr/testify/require"
+)
+
+func TestSlowlog(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{})
+	defer srv.Close()
+	ctx := context.Background()
+	rdb := srv.NewClient()
+	defer func() { require.NoError(t, rdb.Close()) }()
+
+	t.Run("SLOWLOG - check that it starts with an empty log", func(t *testing.T) {
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - only logs commands taking more time than specified", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 100000).Err())

Review Comment:
   ditto others



##########
tests/gocase/unit/slowlog/slowlog_test.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package slowlog
+
+import (
+	"context"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/go-redis/redis/v9"
+	"github.com/stretchr/testify/require"
+)
+
+func TestSlowlog(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{})

Review Comment:
   Default config contains: `slowlog-log-slower-than 1000000`.



##########
tests/gocase/unit/slowlog/slowlog_test.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package slowlog
+
+import (
+	"context"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/go-redis/redis/v9"
+	"github.com/stretchr/testify/require"
+)
+
+func TestSlowlog(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{})
+	defer srv.Close()
+	ctx := context.Background()
+	rdb := srv.NewClient()
+	defer func() { require.NoError(t, rdb.Close()) }()
+
+	t.Run("SLOWLOG - check that it starts with an empty log", func(t *testing.T) {
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - only logs commands taking more time than specified", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 100000).Err())
+		require.NoError(t, rdb.Ping(ctx).Err())
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - max entries is correctly handled", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 0).Err())
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-max-len", 10).Err())
+		for i := 0; i < 100; i++ {
+			require.NoError(t, rdb.Ping(ctx).Err())
+		}
+		require.EqualValues(t, 10, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - GET optional argument to limit output len works", func(t *testing.T) {
+		require.EqualValues(t, 5, reflect.ValueOf(rdb.Do(ctx, "slowlog", "get", 5).Val()).Len())
+	})
+
+	t.Run("SLOWLOG - RESET subcommand works", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 100000).Err())
+		require.NoError(t, rdb.Do(ctx, "slowlog", "reset").Err())
+		require.EqualValues(t, 0, rdb.Do(ctx, "slowlog", "len").Val())
+	})
+
+	t.Run("SLOWLOG - logged entry sanity check", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "client", "setname", "foobar").Err())
+		require.NoError(t, rdb.Do(ctx, "debug", "sleep", 0.2).Err())
+		cmd := rdb.Do(ctx, "slowlog", "get")
+		require.NoError(t, cmd.Err())
+		e := reflect.ValueOf(cmd.Val()).Index(0).Interface()
+		require.EqualValues(t, 4, reflect.ValueOf(e).Len())
+		require.EqualValues(t, 105, reflect.ValueOf(e).Index(0).Interface().(int64))
+		require.EqualValues(t, true, reflect.ValueOf(e).Index(2).Interface().(int64) > 100000)
+		require.EqualValues(t, []interface{}{"debug", "sleep", "0.2"}, reflect.ValueOf(e).Index(3).Interface())
+	})
+
+	t.Run("SLOWLOG - Rewritten commands are logged as their original command", func(t *testing.T) {
+		require.NoError(t, rdb.Do(ctx, "config", "set", "slowlog-log-slower-than", 0).Err())
+		// Test rewriting client arguments
+		require.NoError(t, rdb.SAdd(ctx, "set", "a", "b", "c", "d", "e").Err())
+		require.NoError(t, rdb.Do(ctx, "slowlog", "reset").Err())
+
+		// SPOP is rewritten as DEL when all keys are removed
+		require.NoError(t, rdb.SPopN(ctx, "set", 10).Err())
+		cmd := rdb.Do(ctx, "slowlog", "get")

Review Comment:
   ditto `SlogLogGet`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org