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

tarantool / go-tarantool / 22105359978

17 Feb 2026 03:51PM UTC coverage: 73.777% (-0.4%) from 74.209%
22105359978

Pull #518

github

babyTsakhes
test correct with message and return deleted code
Pull Request #518: conn: change design of tarantool.Logger

185 of 272 new or added lines in 3 files covered. (68.01%)

28 existing lines in 2 files now uncovered.

3123 of 4233 relevant lines covered (73.78%)

9475.75 hits per line

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

78.35
/future.go
1
package tarantool
2

3
import (
4
        "io"
5
        "sync"
6
        "time"
7
)
8

9
// Future is a handle for asynchronous request.
10
type Future struct {
11
        requestId uint32
12
        req       Request
13
        next      *Future
14
        timeout   time.Duration
15
        mutex     sync.Mutex
16
        resp      Response
17
        err       error
18
        cond      sync.Cond
19
        finished  bool
20
        done      chan struct{}
21
}
22

23
func (fut *Future) wait() {
1,908✔
24
        fut.mutex.Lock()
1,908✔
25
        defer fut.mutex.Unlock()
1,908✔
26

1,908✔
27
        for !fut.finished {
3,027✔
28
                fut.cond.Wait()
1,119✔
29
        }
1,119✔
30
}
31

32
func (fut *Future) finish() {
14✔
33
        fut.mutex.Lock()
14✔
34
        defer fut.mutex.Unlock()
14✔
35

14✔
36
        fut.finished = true
14✔
37

14✔
38
        if fut.done != nil {
14✔
UNCOV
39
                close(fut.done)
×
UNCOV
40
        }
×
41

42
        fut.cond.Broadcast()
14✔
43
}
44

45
func (fut *Future) isFinished() bool {
3,727✔
46
        fut.mutex.Lock()
3,727✔
47
        defer fut.mutex.Unlock()
3,727✔
48

3,727✔
49
        return fut.finished
3,727✔
50
}
3,727✔
51

52
// NewFuture creates a new empty Future for a given Request.
53
func NewFuture(req Request) (fut *Future) {
1,884✔
54
        fut = &Future{}
1,884✔
55
        fut.done = nil
1,884✔
56
        fut.finished = false
1,884✔
57
        fut.cond.L = &fut.mutex
1,884✔
58
        fut.req = req
1,884✔
59
        return fut
1,884✔
60
}
1,884✔
61

62
// SetResponse sets a response for the future and finishes the future.
63
func (fut *Future) SetResponse(header Header, body io.Reader) error {
1,855✔
64
        fut.mutex.Lock()
1,855✔
65
        defer fut.mutex.Unlock()
1,855✔
66

1,855✔
67
        if fut.finished {
1,855✔
UNCOV
68
                return nil
×
UNCOV
69
        }
×
70

71
        resp, err := fut.req.Response(header, body)
1,855✔
72
        if err != nil {
1,856✔
73
                return err
1✔
74
        }
1✔
75
        fut.resp = resp
1,854✔
76

1,854✔
77
        fut.finished = true
1,854✔
78

1,854✔
79
        if fut.done != nil {
1,854✔
UNCOV
80
                close(fut.done)
×
UNCOV
81
        }
×
82

83
        fut.cond.Broadcast()
1,854✔
84

1,854✔
85
        return nil
1,854✔
86
}
87

88
// SetError sets an error for the future and finishes the future.
89
func (fut *Future) SetError(err error) {
16✔
90
        fut.mutex.Lock()
16✔
91
        defer fut.mutex.Unlock()
16✔
92

16✔
93
        if fut.finished {
16✔
94
                return
×
95
        }
×
96
        fut.err = err
16✔
97

16✔
98
        fut.finished = true
16✔
99

16✔
100
        if fut.done != nil {
16✔
UNCOV
101
                close(fut.done)
×
UNCOV
102
        }
×
103

104
        fut.cond.Broadcast()
16✔
105
}
106

107
// GetResponse waits for Future to be filled and returns Response and error.
108
//
109
// Note: Response could be equal to nil if ClientError is returned in error.
110
//
111
// "error" could be Error, if it is error returned by Tarantool,
112
// or ClientError, if something bad happens in a client process.
113
func (fut *Future) GetResponse() (Response, error) {
40✔
114
        fut.wait()
40✔
115
        return fut.resp, fut.err
40✔
116
}
40✔
117

118
// Get waits for Future to be filled and returns the data of the Response and error.
119
//
120
// The data will be []interface{}, so if you want more performance, use GetTyped method.
121
//
122
// "error" could be Error, if it is error returned by Tarantool,
123
// or ClientError, if something bad happens in a client process.
124
func (fut *Future) Get() ([]interface{}, error) {
1,208✔
125
        fut.wait()
1,208✔
126
        if fut.err != nil {
1,236✔
127
                return nil, fut.err
28✔
128
        }
28✔
129
        return fut.resp.Decode()
1,180✔
130
}
131

132
// GetTyped waits for Future and calls msgpack.Decoder.Decode(result) if no error happens.
133
// It is could be much faster than Get() function.
134
//
135
// Note: Tarantool usually returns array of tuples (except for Eval and Call17 actions).
136
func (fut *Future) GetTyped(result interface{}) error {
660✔
137
        fut.wait()
660✔
138
        if fut.err != nil {
662✔
139
                return fut.err
2✔
140
        }
2✔
141
        return fut.resp.DecodeTyped(result)
658✔
142
}
143

144
var closedChan = make(chan struct{})
145

146
func init() {
1✔
147
        close(closedChan)
1✔
148
}
1✔
149

150
// WaitChan returns channel which becomes closed when response arrived or error occurred.
UNCOV
151
func (fut *Future) WaitChan() <-chan struct{} {
×
UNCOV
152
        fut.mutex.Lock()
×
UNCOV
153
        defer fut.mutex.Unlock()
×
UNCOV
154

×
UNCOV
155
        if fut.finished {
×
UNCOV
156
                return closedChan
×
UNCOV
157
        }
×
158

UNCOV
159
        if fut.done == nil {
×
UNCOV
160
                fut.done = make(chan struct{})
×
UNCOV
161
        }
×
162

UNCOV
163
        return fut.done
×
164
}
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