MCPcopy
hub / github.com/cbeuw/Cloak / TestUserPanel_UpdateUsageQueue

Function TestUserPanel_UpdateUsageQueue

internal/server/userpanel_test.go:112–190  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

110}
111
112func TestUserPanel_UpdateUsageQueue(t *testing.T) {
113 var tmpDB, _ = ioutil.TempFile("", "ck_user_info")
114 defer os.Remove(tmpDB.Name())
115 mgr, err := usermanager.MakeLocalManager(tmpDB.Name(), mockWorldState)
116 if err != nil {
117 t.Fatal(err)
118 }
119 panel := MakeUserPanel(mgr)
120
121 t.Run("normal update", func(t *testing.T) {
122 _ = mgr.WriteUserInfo(validUserInfo)
123
124 user, err := panel.GetUser(validUserInfo.UID)
125 if err != nil {
126 t.Error(err)
127 }
128
129 user.valve.AddTx(1)
130 user.valve.AddRx(2)
131 panel.updateUsageQueue()
132 err = panel.commitUpdate()
133 if err != nil {
134 t.Error(err)
135 }
136
137 if user.valve.GetRx() != 0 || user.valve.GetTx() != 0 {
138 t.Error("rx and tx stats are not cleared")
139 }
140
141 updatedUinfo, _ := mgr.GetUserInfo(validUserInfo.UID)
142 if *updatedUinfo.DownCredit != *validUserInfo.DownCredit-1 {
143 t.Error("down credit incorrect update")
144 }
145 if *updatedUinfo.UpCredit != *validUserInfo.UpCredit-2 {
146 t.Error("up credit incorrect update")
147 }
148
149 // another update
150 user.valve.AddTx(3)
151 user.valve.AddRx(4)
152 panel.updateUsageQueue()
153 err = panel.commitUpdate()
154 if err != nil {
155 t.Error(err)
156 }
157
158 updatedUinfo, _ = mgr.GetUserInfo(validUserInfo.UID)
159 if *updatedUinfo.DownCredit != *validUserInfo.DownCredit-(1+3) {
160 t.Error("down credit incorrect update")
161 }
162 if *updatedUinfo.UpCredit != *validUserInfo.UpCredit-(2+4) {
163 t.Error("up credit incorrect update")
164 }
165 })
166 t.Run("terminating update", func(t *testing.T) {
167 _ = mgr.WriteUserInfo(validUserInfo)
168
169 user, err := panel.GetUser(validUserInfo.UID)

Callers

nothing calls this directly

Calls 12

MakeLocalManagerFunction · 0.92
MakeUserPanelFunction · 0.85
GetUserMethod · 0.80
updateUsageQueueMethod · 0.80
commitUpdateMethod · 0.80
isActiveMethod · 0.80
WriteUserInfoMethod · 0.65
AddTxMethod · 0.65
AddRxMethod · 0.65
GetRxMethod · 0.65
GetTxMethod · 0.65
GetUserInfoMethod · 0.65

Tested by

no test coverage detected