Merge pull request #784 from nyaxt/avoid_magicnum
Rename IsEtcdConflict to IsEtcdTestFailed
This commit is contained in:
commit
bec27af51a
@ -39,7 +39,7 @@ func MakeAsync(fn WorkFunc) <-chan interface{} {
|
||||
if err != nil {
|
||||
status := http.StatusInternalServerError
|
||||
switch {
|
||||
case tools.IsEtcdConflict(err):
|
||||
case tools.IsEtcdTestFailed(err):
|
||||
status = http.StatusConflict
|
||||
}
|
||||
channel <- &api.Status{
|
||||
|
@ -82,14 +82,14 @@ type EtcdHelper struct {
|
||||
Versioning Versioning
|
||||
}
|
||||
|
||||
// Returns true iff err is an etcd not found error.
|
||||
// IsEtcdNotFound returns true iff err is an etcd not found error.
|
||||
func IsEtcdNotFound(err error) bool {
|
||||
return isEtcdErrorNum(err, 100)
|
||||
return isEtcdErrorNum(err, EtcdErrorCodeNotFound)
|
||||
}
|
||||
|
||||
// Returns true iff err is an etcd write conflict.
|
||||
func IsEtcdConflict(err error) bool {
|
||||
return isEtcdErrorNum(err, 101)
|
||||
// IsEtcdTestFailed returns true iff err is an etcd write conflict.
|
||||
func IsEtcdTestFailed(err error) bool {
|
||||
return isEtcdErrorNum(err, EtcdErrorCodeTestFailed)
|
||||
}
|
||||
|
||||
// IsEtcdWatchStoppedByUser returns true iff err is a client triggered stop.
|
||||
@ -242,7 +242,7 @@ func (h *EtcdHelper) AtomicUpdate(key string, ptrToType interface{}, tryUpdate E
|
||||
return err
|
||||
}
|
||||
_, err = h.Client.CompareAndSwap(key, string(data), 0, origBody, index)
|
||||
if IsEtcdConflict(err) {
|
||||
if IsEtcdTestFailed(err) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
|
@ -50,7 +50,7 @@ func init() {
|
||||
scheme.AddKnownTypes("v1beta1", TestResource{})
|
||||
}
|
||||
|
||||
func TestIsNotFoundErr(t *testing.T) {
|
||||
func TestIsEtcdNotFound(t *testing.T) {
|
||||
try := func(err error, isNotFound bool) {
|
||||
if IsEtcdNotFound(err) != isNotFound {
|
||||
t.Errorf("Expected %#v to return %v, but it did not", err, isNotFound)
|
||||
|
Loading…
Reference in New Issue
Block a user