(t *testing.T)
| 55 | } |
| 56 | |
| 57 | func TestIdBump(t *testing.T) { |
| 58 | dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} |
| 59 | con, err := grpc.NewClient(testutil.GetSockAddrZero(), dialOpts...) |
| 60 | require.NoError(t, err) |
| 61 | zc := pb.NewZeroClient(con) |
| 62 | |
| 63 | ctx := context.Background() |
| 64 | res, err := zc.AssignIds(ctx, &pb.Num{Val: 10, Type: pb.Num_UID}) |
| 65 | require.NoError(t, err) |
| 66 | require.Equal(t, uint64(10), res.GetEndId()-res.GetStartId()+1) |
| 67 | |
| 68 | // Next assignment's startId should be greater than 10. |
| 69 | res, err = zc.AssignIds(ctx, &pb.Num{Val: 50, Type: pb.Num_UID}) |
| 70 | require.NoError(t, err) |
| 71 | require.Greater(t, res.GetStartId(), uint64(10)) |
| 72 | require.Equal(t, uint64(50), res.GetEndId()-res.GetStartId()+1) |
| 73 | |
| 74 | bumpTo := res.GetEndId() + 100000 |
| 75 | |
| 76 | // Bump the lease to (last result + 100000). |
| 77 | _, err = zc.AssignIds(ctx, &pb.Num{Val: bumpTo, Type: pb.Num_UID, Bump: true}) |
| 78 | require.NoError(t, err) |
| 79 | |
| 80 | // Next assignment's startId should be greater than bumpTo. |
| 81 | res, err = zc.AssignIds(ctx, &pb.Num{Val: 10, Type: pb.Num_UID}) |
| 82 | require.NoError(t, err) |
| 83 | require.Greater(t, res.GetStartId(), bumpTo) |
| 84 | require.Equal(t, uint64(10), res.GetEndId()-res.GetStartId()+1) |
| 85 | |
| 86 | // If bump request is less than maxLease, then it should result in no-op. |
| 87 | _, err = zc.AssignIds(ctx, &pb.Num{Val: 10, Type: pb.Num_UID, Bump: true}) |
| 88 | require.Contains(t, err.Error(), "Nothing to be leased") |
| 89 | } |
| 90 | |
| 91 | func TestProposalKey(t *testing.T) { |
| 92 | id := uint64(2) |
nothing calls this directly
no test coverage detected