MCPcopy
hub / github.com/dgraph-io/dgraph / TestProposalKey

Function TestProposalKey

dgraph/cmd/zero/zero_test.go:91–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestProposalKey(t *testing.T) {
92 id := uint64(2)
93 node := &node{Node: &conn.Node{Id: id}, ctx: context.Background(), closer: z.NewCloser(1)}
94 require.NoError(t, node.initProposalKey(node.Id))
95
96 pkey := proposalKey
97 nodeIdFromKey := proposalKey >> 48
98 require.Equal(t, id, nodeIdFromKey, "id extracted from proposal key is not equal to initial value")
99
100 valueOf48thBit := int(pkey & (1 << 48))
101 require.Equal(t, 0, valueOf48thBit, "48th bit is not set to zero on initialisation")
102
103 node.uniqueKey()
104 require.Equal(t, pkey+1, proposalKey, "proposal key should increment by 1 at each call of unique key")
105
106 uniqueKeys := make(map[uint64]struct{})
107 for i := 0; i < 10; i++ {
108 node.uniqueKey()
109 uniqueKeys[proposalKey] = struct{}{}
110 }
111 require.Equal(t, len(uniqueKeys), 10, "each iteration should create unique key")
112}
113
114func TestZeroHealth(t *testing.T) {
115 client := http.Client{Timeout: 3 * time.Second}

Callers

nothing calls this directly

Calls 2

initProposalKeyMethod · 0.95
uniqueKeyMethod · 0.95

Tested by

no test coverage detected