• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heathcliff26 / valkey-keepalived / 13485711033

23 Feb 2025 06:22PM UTC coverage: 92.114% (+11.4%) from 80.757%
13485711033

push

github

heathcliff26
Improve test coverage

Add more test coverage in all packages.
Use miniredis where possible to improve test performance and reliability.

Signed-off-by: Heathcliff <heathcliff@heathcliff.eu>

5 of 7 new or added lines in 3 files covered. (71.43%)

292 of 317 relevant lines covered (92.11%)

1.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/pkg/failover-client/node.go
1
package failoverclient
2

3
import (
4
        "context"
5
        "fmt"
6
        "log/slog"
7

8
        "github.com/valkey-io/valkey-go"
9
)
10

11
type node struct {
12
        address string
13
        port    int64
14
        runID   string
15
        up      bool
16
        client  valkey.Client
17
}
18

19
const failedToConnectToNodeMsg = "Failed to connect to node"
20

21
// Connect to valkey and retrieve the run_id
22
func (n *node) connect(ctx context.Context, option valkey.ClientOption) error {
1✔
23
        client, err := newValkeyClient(n.address, n.port, option)
1✔
24
        if err != nil {
2✔
25
                return err
1✔
26
        }
1✔
27

28
        res, err := client.Do(ctx, client.B().Info().Section("server").Build()).ToString()
1✔
29
        if err != nil {
2✔
30
                client.Close()
1✔
31
                return err
1✔
32
        }
1✔
33

34
        n.runID = parseRunIDFromInfo(res)
1✔
35
        n.client = client
1✔
36
        n.up = true
1✔
37

1✔
38
        return nil
1✔
39
}
40

41
// Check that the node is up.
42
// Requires client to be present.
43
func (n *node) ping(ctx context.Context) {
1✔
44
        res, err := n.client.Do(ctx, n.client.B().Ping().Build()).ToString()
1✔
45
        if err != nil || res != "PONG" {
2✔
46
                if n.up {
2✔
47
                        slog.Info("Node is DOWN", slog.String("node", n.address), "err", err, slog.String("res", res))
1✔
48
                        n.up = false
1✔
49
                }
1✔
50
                n.client.Close()
1✔
51
                n.client = nil
1✔
52
        } else if !n.up {
2✔
53
                n.up = true
1✔
54
                slog.Info("Node is UP", slog.String("node", n.address))
1✔
55
        }
1✔
56
}
57

58
// Make this node a master node
59
func (n *node) master(ctx context.Context) error {
1✔
60
        if n.client == nil {
1✔
NEW
61
                return fmt.Errorf("node is not up")
×
62
        }
×
63

64
        return n.client.Do(ctx, n.client.B().Replicaof().No().One().Build()).Error()
1✔
65
}
66

67
// Make this node a slave of the given master
68
func (n *node) slave(ctx context.Context, master string) error {
1✔
69
        if n.client == nil {
2✔
70
                slog.Debug("Node is not up, skipping for update", slog.String("node", n.address))
1✔
71
                return nil
1✔
72
        }
1✔
73

74
        return n.client.Do(ctx, n.client.B().Replicaof().Host(master).Port(n.port).Build()).Error()
1✔
75
}
76

77
// Close the open client
78
func (n *node) close() {
1✔
79
        if n.client != nil {
2✔
80
                n.client.Close()
1✔
81
                n.client = nil
1✔
82
        }
1✔
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc