Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Conversation

@gdbelvin
Copy link
Contributor

@gdbelvin gdbelvin commented May 1, 2018

This PR addresses some mid-CreateDomain issues that were cropping up in production and seeks to increase test cases coverage.

  • Handle the AlreadyExists Case
  • Handle a mid-tree creation failure by deleting other tree.
  • Add unit testing with mocks.

@gdbelvin gdbelvin requested a review from phad May 1, 2018 14:37
* Handle the AlreadyExists Case
* Handle a mid-tree creation failure by deleting other tree.
* Add unit testing with mocks.
@codecov-io
Copy link

codecov-io commented May 1, 2018

Codecov Report

Merging #969 into master will increase coverage by 0.41%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #969      +/-   ##
==========================================
+ Coverage   46.92%   47.34%   +0.41%     
==========================================
  Files          28       28              
  Lines        2018     2034      +16     
==========================================
+ Hits          947      963      +16     
- Misses        892      894       +2     
+ Partials      179      177       -2
Impacted Files Coverage Δ
core/monitor/monitor.go 17.72% <0%> (-0.95%) ⬇️
impl/sql/domain/storage.go 68.04% <66.66%> (-1.44%) ⬇️
core/adminserver/admin_server.go 56.75% <88.88%> (+7.48%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26b3b89...35cd177. Read the comment docs.

@gdbelvin gdbelvin added this to the Productionize milestone May 1, 2018
@gdbelvin
Copy link
Contributor Author

gdbelvin commented May 2, 2018

More unit tests for Key Transparency. PTAL

@gdbelvin
Copy link
Contributor Author

gdbelvin commented May 4, 2018

PTAL

}

type miniEnv struct {
s *testonly.MockServer
Copy link
Contributor

Choose a reason for hiding this comment

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

's' is a bit ambiguous given that it's a MockServer and just below you have an actual Server.
How about 'ms' or 'mockSrv'?

Copy link
Contributor

Choose a reason for hiding this comment

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

And below you call something associated with it stopFakeServer.
So is it a fake server?

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'll rename to ms. It's a mock server.

if _, delErr := s.logAdmin.DeleteTree(ctx, &tpb.DeleteTreeRequest{TreeId: logTree.TreeId}); delErr != nil {
return nil, status.Errorf(codes.Internal, "adminserver: CreateAndInitTree(map): %v, DeleteTree(%v): %v ", err, logTree.TreeId, delErr)
}
if _, delErr := s.mapAdmin.DeleteTree(ctx, &tpb.DeleteTreeRequest{TreeId: mapTree.TreeId}); delErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if in this case you ought to try deleting both the log and the map, and return a single error from which ever one fails?

i.e. if deleting the log fails, note that but also try deleting the map.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea. Fewer if statements is always better.

e.s.Admin.EXPECT().CreateTree(gomock.Any(), gomock.Any()).Return(&tpb.Tree{TreeType: tpb.TreeType_MAP}, nil)
e.s.Map.EXPECT().InitMap(gomock.Any(), gomock.Any()).Return(&tpb.InitMapResponse{}, fmt.Errorf("init map failure")).MinTimes(1)
e.s.Map.EXPECT().InitMap(gomock.Any(), gomock.Any()).Return(&tpb.InitMapResponse{}, nil)
e.s.Map.EXPECT().GetSignedMapRootByRevision(gomock.Any(), gomock.Any()).Return(&tpb.GetSignedMapRootResponse{}, fmt.Errorf("not found")).MinTimes(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation looks screwy here but it's probably Github's fault, I can't tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's some long lines, I'll wrap them.

e.s.Log.EXPECT().GetLatestSignedLogRoot(gomock.Any(), gomock.Any()).Return(&tpb.GetLatestSignedLogRootResponse{}, nil)
e.s.Admin.EXPECT().CreateTree(gomock.Any(), gomock.Any()).Return(&tpb.Tree{TreeType: tpb.TreeType_MAP}, nil)
e.s.Map.EXPECT().InitMap(gomock.Any(), gomock.Any()).Return(&tpb.InitMapResponse{}, nil)
e.s.Map.EXPECT().GetSignedMapRootByRevision(gomock.Any(), gomock.Any()).Return(&tpb.GetSignedMapRootResponse{}, nil).MinTimes(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

same thing here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrapped now

},
},
{
desc: "init fails",
Copy link
Contributor

Choose a reason for hiding this comment

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

the desc doesn't really describe what you're testing.
In the circumstance where init fails you try to delete the log & the map.
That's what the test is checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@phad phad left a comment

Choose a reason for hiding this comment

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

LGTM

@gdbelvin gdbelvin merged commit bd03737 into google:master May 4, 2018
@gdbelvin gdbelvin deleted the fix/createtree branch May 4, 2018 16:09
gdbelvin added a commit to gdbelvin/keytransparency that referenced this pull request May 8, 2018
…y into test/listhistory

* 'test/listhistory' of github.com:gdbelvin/keytransparency:
  Use DomainID rather than mapID during authorization (google#970)
  Strengthen CreateDomain (google#969)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants