MCPcopy
hub / github.com/olric-data/olric / newTestOlricWithConfig

Function newTestOlricWithConfig

olric_test.go:34–74  ·  view source on GitHub ↗

newTestOlricWithConfig creates a new Olric instance with the given configuration. This function is intended for internal use. Please use testOlricCluster and its methods to form a cluster in tests.

(t *testing.T, c *config.Config)

Source from the content-addressed store, hash-verified

32// This function is intended for internal use. Please use testOlricCluster and its
33// methods to form a cluster in tests.
34func newTestOlricWithConfig(t *testing.T, c *config.Config) *Olric {
35 port, err := testutil.GetFreePort()
36 require.NoError(t, err)
37
38 if c.MemberlistConfig == nil {
39 c.MemberlistConfig = memberlist.DefaultLocalConfig()
40 }
41 c.MemberlistConfig.BindPort = 0
42
43 c.BindAddr = "127.0.0.1"
44 c.BindPort = port
45
46 err = c.Sanitize()
47 require.NoError(t, err)
48
49 err = c.Validate()
50 require.NoError(t, err)
51
52 ctx, cancel := context.WithCancel(context.Background())
53 c.Started = func() {
54 cancel()
55 }
56
57 db, err := New(c)
58 require.NoError(t, err)
59
60 go func() {
61 if err := db.Start(); err != nil {
62 panic(fmt.Sprintf("Failed to run Olric: %v", err))
63 }
64 }()
65
66 select {
67 case <-time.After(time.Second):
68 t.Fatalf("Olric cannot be started in one second")
69 case <-ctx.Done():
70 // everything is fine
71 }
72
73 return db
74}
75
76type testOlricCluster struct {
77 mtx sync.Mutex

Callers 1

addMemberWithConfigMethod · 0.85

Calls 5

GetFreePortFunction · 0.92
NewFunction · 0.70
SanitizeMethod · 0.65
ValidateMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected