Skip to content

Commit

Permalink
fixed concurrency bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Mar 6, 2021
1 parent c928e32 commit 0e20e25
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 84 deletions.
132 changes: 68 additions & 64 deletions coverage.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
mode: set
github.com/Ulbora/cocka2notesApi/user.go:30.47,35.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:44.2,45.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:35.16,40.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:40.15,42.4 1 1
github.com/Ulbora/cocka2notesApi/user.go:49.50,54.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:63.2,64.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:54.16,59.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:59.15,61.4 1 1
github.com/Ulbora/cocka2notesApi/user.go:68.58,73.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:82.2,83.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:73.16,78.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:78.15,80.4 1 1
github.com/Ulbora/cocka2notesApi/user.go:87.79,100.2 9 1
github.com/Ulbora/cocka2notesApi/user.go:103.48,115.2 8 1
github.com/Ulbora/cocka2notesApi/user.go:118.50,123.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:129.2,131.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:123.16,128.3 4 1
github.com/Ulbora/cocka2notesApi/user.go:135.53,140.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:149.2,150.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:140.16,145.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:145.15,147.4 1 1
github.com/Ulbora/cocka2notesApi/api.go:66.49,69.22 3 1
github.com/Ulbora/cocka2notesApi/api.go:72.2,72.24 1 1
github.com/Ulbora/cocka2notesApi/api.go:69.22,71.3 1 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:32.70,37.16 5 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:50.2,51.13 2 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:37.16,42.11 5 1
Expand Down Expand Up @@ -88,67 +112,47 @@ github.com/Ulbora/cocka2notesApi/noteItem.go:117.29,118.38 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:118.38,124.10 4 1
github.com/Ulbora/cocka2notesApi/noteItem.go:131.56,133.2 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:136.59,138.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:48.33,57.2 6 1
github.com/Ulbora/cocka2notesApi/notesApi.go:60.44,62.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:64.106,65.20 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:68.2,70.37 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:76.2,77.16 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:83.2,83.12 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:65.20,67.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:70.37,73.3 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:73.8,75.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:77.16,78.37 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:78.37,81.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:87.43,89.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:92.43,94.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:97.42,99.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:102.45,104.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:107.50,109.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:112.39,113.44 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:131.2,131.47 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:149.2,149.36 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:167.2,167.39 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:113.44,117.48 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:124.3,125.10 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:117.48,120.20 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:120.20,122.5 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:125.10,128.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:131.47,135.51 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:142.3,143.10 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:135.51,138.20 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:138.20,140.5 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:143.10,146.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:149.36,153.40 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:160.3,161.10 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:153.40,156.20 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:156.20,158.5 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:161.10,164.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:167.39,171.43 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:178.3,179.10 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:171.43,174.20 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:174.20,176.5 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:179.10,182.4 2 1
github.com/Ulbora/cocka2notesApi/user.go:30.47,35.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:44.2,45.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:35.16,40.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:40.15,42.4 1 1
github.com/Ulbora/cocka2notesApi/user.go:49.50,54.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:63.2,64.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:54.16,59.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:59.15,61.4 1 1
github.com/Ulbora/cocka2notesApi/user.go:68.58,73.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:82.2,83.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:73.16,78.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:78.15,80.4 1 1
github.com/Ulbora/cocka2notesApi/user.go:87.79,100.2 9 1
github.com/Ulbora/cocka2notesApi/user.go:103.48,115.2 8 1
github.com/Ulbora/cocka2notesApi/user.go:118.50,123.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:129.2,131.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:123.16,128.3 4 1
github.com/Ulbora/cocka2notesApi/user.go:135.53,140.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:149.2,150.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:140.16,145.15 5 1
github.com/Ulbora/cocka2notesApi/user.go:145.15,147.4 1 1
github.com/Ulbora/cocka2notesApi/api.go:66.49,69.22 3 1
github.com/Ulbora/cocka2notesApi/api.go:72.2,72.24 1 1
github.com/Ulbora/cocka2notesApi/api.go:69.22,71.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:49.33,58.2 6 1
github.com/Ulbora/cocka2notesApi/notesApi.go:61.44,63.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:65.106,66.20 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:69.2,71.37 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:77.2,78.16 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:84.2,84.12 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:66.20,68.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:71.37,74.3 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:74.8,76.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:78.16,79.37 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:79.37,82.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:88.43,90.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:93.43,95.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:98.42,100.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:103.45,105.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:108.50,110.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:113.39,114.44 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:139.2,139.47 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:164.2,164.36 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:189.2,189.39 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:114.44,119.48 5 1
github.com/Ulbora/cocka2notesApi/notesApi.go:130.3,133.10 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:119.48,121.33 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:121.33,125.21 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:125.21,127.6 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:133.10,136.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:139.47,144.51 5 1
github.com/Ulbora/cocka2notesApi/notesApi.go:155.3,158.10 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:144.51,146.33 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:146.33,150.21 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:150.21,152.6 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:158.10,161.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:164.36,169.40 5 1
github.com/Ulbora/cocka2notesApi/notesApi.go:180.3,183.10 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:169.40,171.25 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:171.25,175.21 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:175.21,177.6 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:183.10,186.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:189.39,194.43 5 1
github.com/Ulbora/cocka2notesApi/notesApi.go:205.3,208.10 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:194.43,196.25 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:196.25,200.21 4 1
github.com/Ulbora/cocka2notesApi/notesApi.go:200.21,202.6 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:208.10,211.4 2 1
69 changes: 49 additions & 20 deletions notesApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package cocka2notesapi
import (
"bytes"
"net/http"
"sync"

px "github.com/Ulbora/GoProxy"
lg "github.com/Ulbora/Level_Logger"
Expand Down Expand Up @@ -114,13 +115,20 @@ func (a *NotesAPI) FlushFailedCache() {
a.log.Debug("FailAddCheckboxNoteItemList: ", a.FailAddCheckboxNoteItemList)
var suc = true
a.retryCall = true
var wg sync.WaitGroup
for i := range a.FailAddCheckboxNoteItemList {
res := a.AddCheckboxItem(&a.FailAddCheckboxNoteItemList[i])
a.log.Debug("AddCheckboxItem suc: ", res.Success)
if !res.Success {
suc = false
}
wg.Add(1)
go func(cb CheckboxNoteItem) {
defer wg.Done()
res := a.AddCheckboxItem(&cb)
a.log.Debug("AddCheckboxItem suc: ", res.Success)
if !res.Success {
suc = false
}
}(a.FailAddCheckboxNoteItemList[i])
}
a.log.Debug("waiting for go routines in add checkitem")
wg.Wait()
a.retryCall = false
if suc {
a.FailAddCheckboxNoteItemList = a.FailAddCheckboxNoteItemList[:0]
Expand All @@ -132,13 +140,20 @@ func (a *NotesAPI) FlushFailedCache() {
a.log.Debug("FailUpdateCheckboxNoteItemList: ", a.FailUpdateCheckboxNoteItemList)
var suc = true
a.retryCall = true
var wg sync.WaitGroup
for i := range a.FailUpdateCheckboxNoteItemList {
res := a.UpdateCheckboxItem(&a.FailUpdateCheckboxNoteItemList[i])
a.log.Debug("UpdateCheckboxItem suc: ", res.Success)
if !res.Success {
suc = false
}
wg.Add(1)
go func(cb CheckboxNoteItem) {
defer wg.Done()
res := a.UpdateCheckboxItem(&cb)
a.log.Debug("UpdateCheckboxItem suc: ", res.Success)
if !res.Success {
suc = false
}
}(a.FailUpdateCheckboxNoteItemList[i])
}
a.log.Debug("waiting for go routines in update checkitem")
wg.Wait()
a.retryCall = false
if suc {
a.FailUpdateCheckboxNoteItemList = a.FailUpdateCheckboxNoteItemList[:0]
Expand All @@ -150,13 +165,20 @@ func (a *NotesAPI) FlushFailedCache() {
a.log.Debug("FailAddNoteItemList: ", a.FailAddNoteItemList)
var suc = true
a.retryCall = true
var wg sync.WaitGroup
for i := range a.FailAddNoteItemList {
res := a.AddNoteItem(&a.FailAddNoteItemList[i])
a.log.Debug("AddNoteItem suc: ", res.Success)
if !res.Success {
suc = false
}
wg.Add(1)
go func(ni NoteItem) {
defer wg.Done()
res := a.AddNoteItem(&ni)
a.log.Debug("AddNoteItem suc: ", res.Success)
if !res.Success {
suc = false
}
}(a.FailAddNoteItemList[i])
}
a.log.Debug("waiting for go routines in add item")
wg.Wait()
a.retryCall = false
if suc {
a.FailAddNoteItemList = a.FailAddNoteItemList[:0]
Expand All @@ -168,13 +190,20 @@ func (a *NotesAPI) FlushFailedCache() {
a.log.Debug("FailUpdateNoteItemList: ", a.FailUpdateNoteItemList)
var suc = true
a.retryCall = true
var wg sync.WaitGroup
for i := range a.FailUpdateNoteItemList {
res := a.UpdateNoteItem(&a.FailUpdateNoteItemList[i])
a.log.Debug("UpdateNoteItem suc: ", res.Success)
if !res.Success {
suc = false
}
wg.Add(1)
go func(ni NoteItem) {
defer wg.Done()
res := a.UpdateNoteItem(&ni)
a.log.Debug("UpdateNoteItem suc: ", res.Success)
if !res.Success {
suc = false
}
}(a.FailUpdateNoteItemList[i])
}
a.log.Debug("waiting for go routines in update item")
wg.Wait()
a.retryCall = false
if suc {
a.FailUpdateNoteItemList = a.FailUpdateNoteItemList[:0]
Expand Down

0 comments on commit 0e20e25

Please sign in to comment.