Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rawscan's test cases are not comprehensive enough to test all boundary conditions #321

Open
awfeequdng opened this issue Nov 24, 2021 · 3 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@awfeequdng
Copy link

在测试用例TestRawScanAfterRawPut1中,RawScanRequest的起始key从put的第一个可以值开始扫描,没有测试从中间某个key开始扫描,因此就导致了有些程序错误而测试用例通过的情况。例如:

  • 当我在RawScan中获取迭代器iterator时,在返回前我先调用迭代器的Rewind,此时迭代器默认的item就是第一个元素,并且在RawScan中不调用Seek函数来定位初始的key,此时就默认从第一个key开始扫描,我们的测试用例可以正常通过;
  • 单当我们的起始key为中间的某个key时,我上面写的代码还是从第一个key开始扫描,这种场景就不会通过(这种测试用例没有实现,因此测不出我的问题)。
@awfeequdng
Copy link
Author

针对以上问题,我添加了如下测试用例:


func TestRawScanStartFromMiddle1(t *testing.T) {
	conf := config.NewTestConfig()
	s := standalone_storage.NewStandAloneStorage(conf)
	s.Start()
	server := NewServer(s)
	defer cleanUpTestData(conf)
	defer s.Stop()

	cf := engine_util.CfDefault
	assert.Nil(t, Set(s, cf, []byte{1}, []byte{233, 1}))
	assert.Nil(t, Set(s, cf, []byte{2}, []byte{233, 2}))
	assert.Nil(t, Set(s, cf, []byte{3}, []byte{233, 3}))
	assert.Nil(t, Set(s, cf, []byte{4}, []byte{233, 4}))

	put := &kvrpcpb.RawPutRequest{
		Key:   []byte{5},
		Value: []byte{233, 5},
		Cf:    cf,
	}

	scan := &kvrpcpb.RawScanRequest{
		StartKey: []byte{3},
		Limit:    10,
		Cf:       cf,
	}

	expectedKeys := [][]byte{{3}, {4}, {5}}

	_, err := server.RawPut(nil, put)
	assert.Nil(t, err)

	resp, err := server.RawScan(nil, scan)
	assert.Nil(t, err)
	assert.Equal(t, len(expectedKeys), len(resp.Kvs))
	for i, kv := range resp.Kvs {
		assert.Equal(t, expectedKeys[i], kv.Key)
		assert.Equal(t, append([]byte{233}, expectedKeys[i]...), kv.Value)
	}
}

@Connor1996
Copy link
Collaborator

Welcome to file a PR to add the test case

@yanguwan yanguwan added good first issue Good for newcomers help wanted Extra attention is needed labels Jun 2, 2022
@yanguwan
Copy link
Contributor

yanguwan commented Jun 2, 2022

@awfeequdng please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants