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

heathcliff26 / valkey-keepalived / 13482055323

23 Feb 2025 10:16AM UTC coverage: 78.947% (-1.0%) from 79.934%
13482055323

push

github

heathcliff26
Add basic e2e test

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

2 of 2 new or added lines in 1 file covered. (100.0%)

3 existing lines in 1 file now uncovered.

240 of 304 relevant lines covered (78.95%)

0.96 hits per line

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

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

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

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

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

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

20
func (n *node) connect(ctx context.Context, option valkey.ClientOption) error {
1✔
21
        client, err := newValkeyClient(n.address, n.port, option)
1✔
22
        if err != nil {
2✔
23
                return err
1✔
24
        }
1✔
25

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

32
        n.runID = parseRunIDFromInfo(res)
1✔
33
        n.client = client
1✔
34
        n.up = true
1✔
35

1✔
36
        return nil
1✔
37
}
38

39
func (n *node) ping(ctx context.Context) {
1✔
40
        res, err := n.client.Do(ctx, n.client.B().Ping().Build()).ToString()
1✔
41
        if err != nil || res != "PONG" {
2✔
42
                if n.up {
2✔
43
                        slog.Info("Node is DOWN", slog.String("node", n.address), "err", err, slog.String("res", res))
1✔
44
                        n.up = false
1✔
45
                }
1✔
46
                n.client.Close()
1✔
47
                n.client = nil
1✔
48
        } else if !n.up {
1✔
49
                n.up = true
×
50
                slog.Info("Node is UP", slog.String("node", n.address))
×
51
        }
×
52
}
53

54
func (n *node) master(ctx context.Context) error {
1✔
55
        if n.client == nil {
1✔
56
                slog.Debug("Node is not up, skipping for update", slog.String("node", n.address))
×
57
                return nil
×
58
        }
×
59

60
        return n.client.Do(ctx, n.client.B().Replicaof().No().One().Build()).Error()
1✔
61
}
62

63
func (n *node) slave(ctx context.Context, master string) error {
1✔
64
        if n.client == nil {
2✔
65
                slog.Debug("Node is not up, skipping for update", slog.String("node", n.address))
1✔
66
                return nil
1✔
67
        }
1✔
68

69
        return n.client.Do(ctx, n.client.B().Replicaof().Host(master).Port(n.port).Build()).Error()
1✔
70
}
71

72
func (n *node) close() {
×
73
        if n.client != nil {
×
74
                n.client.Close()
×
75
                n.client = nil
×
76
        }
×
77
}
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