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

Implement agent handler saveIndex test case #1731

Merged
merged 25 commits into from
Sep 27, 2022

Conversation

kevindiu
Copy link
Contributor

@kevindiu kevindiu commented Jul 12, 2022

Signed-off-by: kevindiu [email protected]

Description:

This PR implements saveIndex test cases.
It updates the args, fields, want and the defaultCheckFunc from the generated test stub.

  1. removed context from args and create it in test code to ensure that the context is handled correctly in test code.
for _, tc := range tests {
	test := tc
	t.Run(test.name, func(tt *testing.T) {
		tt.Parallel()

		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		// use of ctx in test
...
  1. fields are changed to the functional options and configurations to initialize server instance.
// before
type fields struct {
	name              string
	ip                string
	ngt               service.NGT
	eg                errgroup.Group
	streamConcurrency int
}

// after
// functional options to initialize server struct
type fields struct {
	srvOpts   []Option
	svcCfg    *config.NGT
	svcOpts   []service.Option
	indexPath string // index path for svcOpts
}
  1. want and defaultCheckFunc are updated to check the error code only in the test case, otherwise it is very hard to ensure the correct error is produce by the function.
type want struct {
	// check errCode instead of error
	errCode codes.Code
}

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.18.3
  • Docker Version: 20.10.8
  • Kubernetes Version: 1.22.0
  • NGT Version: 1.14.6

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@kevindiu kevindiu requested a review from vankichi July 12, 2022 09:51
@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - replace the PR body by changelog details
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase master
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

@codecov
Copy link

codecov bot commented Jul 12, 2022

Codecov Report

Base: 30.29% // Head: 30.38% // Increases project coverage by +0.08% 🎉

Coverage data is based on head (36c57c9) compared to base (2abca95).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1731      +/-   ##
==========================================
+ Coverage   30.29%   30.38%   +0.08%     
==========================================
  Files         370      370              
  Lines       33689    33689              
==========================================
+ Hits        10206    10235      +29     
+ Misses      23062    23040      -22     
+ Partials      421      414       -7     
Impacted Files Coverage Δ
internal/net/http/middleware/timeout.go 91.11% <0.00%> (-2.23%) ⬇️
internal/worker/worker.go 83.07% <0.00%> (+0.76%) ⬆️
internal/worker/queue.go 100.00% <0.00%> (+1.26%) ⬆️
pkg/agent/core/ngt/service/option.go 91.41% <0.00%> (+1.84%) ⬆️
...ent/core/ngt/service/vqueue/undeleted_index_map.go 73.88% <0.00%> (+5.55%) ⬆️
...nt/core/ngt/service/vqueue/uninserted_index_map.go 78.68% <0.00%> (+8.19%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@vankichi vankichi requested review from a team and datelier and removed request for a team July 14, 2022 04:42
@kevindiu kevindiu force-pushed the test/pkg/add-pkg-agent-handler-save-index-test branch from 2bc9812 to be3becc Compare July 21, 2022 05:04
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 21, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 36c57c9
Status: ✅  Deploy successful!
Preview URL: https://71687013.vald.pages.dev
Branch Preview URL: https://test-pkg-add-pkg-agent-handl-f7mh.vald.pages.dev

View logs

Copy link
Contributor

@vankichi vankichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM about case

Copy link
Contributor

@datelier datelier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevindiu kevindiu changed the base branch from master to main August 15, 2022 02:36
@kevindiu kevindiu force-pushed the test/pkg/add-pkg-agent-handler-save-index-test branch from 6afc6b5 to a3048a4 Compare August 18, 2022 01:56
@kevindiu kevindiu force-pushed the test/pkg/add-pkg-agent-handler-save-index-test branch from 9c8ae91 to b92f0f8 Compare September 8, 2022 04:13
pkg/agent/core/ngt/handler/grpc/index_test.go Outdated Show resolved Hide resolved
pkg/agent/core/ngt/handler/grpc/index_test.go Outdated Show resolved Hide resolved
pkg/agent/core/ngt/handler/grpc/index_test.go Outdated Show resolved Hide resolved
checkBackupFolder := func(fields fields, ctx context.Context, wantVecs []*payload.Insert_Request) error {
// create another server instance to check if any vector is inserted and saved to the backup dir
eg, _ := errgroup.New(ctx)
ngt, err := service.New(fields.svcCfg, append(fields.svcOpts,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Function New->mktmp->initNGT should pass the context parameter (contextcheck)

@kevindiu kevindiu force-pushed the test/pkg/add-pkg-agent-handler-save-index-test branch 2 times, most recently from 220e937 to a5846ba Compare September 8, 2022 06:54
@kevindiu kevindiu changed the title [WIP] Implement agent handler saveIndex test case Implement agent handler saveIndex test case Sep 15, 2022
@kevindiu kevindiu marked this pull request as ready for review September 15, 2022 07:37
pkg/agent/core/ngt/handler/grpc/index_test.go Outdated Show resolved Hide resolved
defaultAfterFunc := func(test test) {
os.RemoveAll(test.fields.indexPath)
}
checkBackupFolder := func(fields fields, ctx context.Context, wantVecs []*payload.Insert_Request) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add the description when it is used.
And, i think it would be better to move it into the defaultCheckFunc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot be moved to defaultCheckFunc because we need the wantVecs, which is created in the test function.
e.g. https://github.com/vdaas/vald/pull/1731/files#diff-86c3d3eae3293a28f5a4f5d3b45b9e0ec9c6654f36980af45bf9111f6a3fa22dR908

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add the discription?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added :)

@@ -508,106 +508,529 @@ func Test_server_CreateIndex(t *testing.T) {
func Test_server_SaveIndex(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
in1 *payload.Empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you update this value to more understandable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry that I cant understand what you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by rename it to in

},
}
}(),
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please format coding style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean writing it as

func() test {
   ....
}(),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

pkg/agent/core/ngt/handler/grpc/index_test.go Outdated Show resolved Hide resolved
Signed-off-by: kevindiu <[email protected]>
@kevindiu kevindiu requested a review from vankichi September 20, 2022 09:09
@kevindiu kevindiu requested review from a team and hlts2 and removed request for datelier and a team September 22, 2022 05:10
Comment on lines 780 to 801
timeout := time.After(10 * time.Second)
ticker := time.Tick(10 * time.Millisecond)
for {
select {
case <-timeout:
// execute save index twice
go s.SaveIndex(ctx, emptyPayload)

gotRes, err := s.SaveIndex(ctx, emptyPayload)
if err := defaultCheckFunc(t, ctx, s, n, w, gotRes, err); err != nil {
return err
}
case <-ticker:
// execute save index twice
go s.SaveIndex(ctx, emptyPayload)

gotRes, err := s.SaveIndex(ctx, emptyPayload)
if err := defaultCheckFunc(t, ctx, s, n, w, gotRes, err); err == nil {
return nil
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain the background of this implementation? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we cannot guarantee the first saveIndex call on line 773 is executed asynchronously when we execute the actual saveIndex call on line 1041, I wanted to check it multiple times when it is not happen.

@kevindiu kevindiu requested a review from hlts2 September 26, 2022 04:10
Signed-off-by: kevindiu <[email protected]>
@kevindiu kevindiu requested a review from hlts2 September 26, 2022 08:56
@kevindiu kevindiu merged commit 364f902 into main Sep 27, 2022
@kevindiu kevindiu deleted the test/pkg/add-pkg-agent-handler-save-index-test branch September 27, 2022 08:09
@kevindiu kevindiu mentioned this pull request Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants