Skip to content

Commit f387862

Browse files
committed
Merge branch 'master' into move-login-out-of-models
2 parents 66cb90f + e83abfc commit f387862

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ test: test-frontend test-backend
359359

360360
.PHONY: test-backend
361361
test-backend:
362-
@echo "Running go test with -tags '$(TEST_TAGS)'..."
362+
@echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
363363
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' $(GO_PACKAGES)
364364

365365
.PHONY: test-frontend
@@ -389,7 +389,7 @@ coverage:
389389

390390
.PHONY: unit-test-coverage
391391
unit-test-coverage:
392-
@echo "Running unit-test-coverage -tags '$(TEST_TAGS)'..."
392+
@echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
393393
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
394394

395395
.PHONY: vendor

modules/queue/queue_disk_channel_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package queue
66

77
import (
88
"io/ioutil"
9+
"sync"
910
"testing"
1011

1112
"code.gitea.io/gitea/modules/util"
@@ -22,6 +23,7 @@ func TestPersistableChannelQueue(t *testing.T) {
2223
}
2324
}
2425

26+
lock := sync.Mutex{}
2527
queueShutdown := []func(){}
2628
queueTerminate := []func(){}
2729

@@ -41,8 +43,12 @@ func TestPersistableChannelQueue(t *testing.T) {
4143
assert.NoError(t, err)
4244

4345
go queue.Run(func(shutdown func()) {
46+
lock.Lock()
47+
defer lock.Unlock()
4448
queueShutdown = append(queueShutdown, shutdown)
4549
}, func(terminate func()) {
50+
lock.Lock()
51+
defer lock.Unlock()
4652
queueTerminate = append(queueTerminate, terminate)
4753
})
4854

@@ -69,7 +75,11 @@ func TestPersistableChannelQueue(t *testing.T) {
6975
assert.Error(t, err)
7076

7177
// Now shutdown the queue
72-
for _, callback := range queueShutdown {
78+
lock.Lock()
79+
callbacks := make([]func(), len(queueShutdown))
80+
copy(callbacks, queueShutdown)
81+
lock.Unlock()
82+
for _, callback := range callbacks {
7383
callback()
7484
}
7585

@@ -87,7 +97,11 @@ func TestPersistableChannelQueue(t *testing.T) {
8797
}
8898

8999
// terminate the queue
90-
for _, callback := range queueTerminate {
100+
lock.Lock()
101+
callbacks = make([]func(), len(queueTerminate))
102+
copy(callbacks, queueTerminate)
103+
lock.Unlock()
104+
for _, callback := range callbacks {
91105
callback()
92106
}
93107

@@ -110,8 +124,12 @@ func TestPersistableChannelQueue(t *testing.T) {
110124
assert.NoError(t, err)
111125

112126
go queue.Run(func(shutdown func()) {
127+
lock.Lock()
128+
defer lock.Unlock()
113129
queueShutdown = append(queueShutdown, shutdown)
114130
}, func(terminate func()) {
131+
lock.Lock()
132+
defer lock.Unlock()
115133
queueTerminate = append(queueTerminate, terminate)
116134
})
117135

@@ -122,10 +140,19 @@ func TestPersistableChannelQueue(t *testing.T) {
122140
result4 := <-handleChan
123141
assert.Equal(t, test2.TestString, result4.TestString)
124142
assert.Equal(t, test2.TestInt, result4.TestInt)
125-
for _, callback := range queueShutdown {
143+
144+
lock.Lock()
145+
callbacks = make([]func(), len(queueShutdown))
146+
copy(callbacks, queueShutdown)
147+
lock.Unlock()
148+
for _, callback := range callbacks {
126149
callback()
127150
}
128-
for _, callback := range queueTerminate {
151+
lock.Lock()
152+
callbacks = make([]func(), len(queueTerminate))
153+
copy(callbacks, queueTerminate)
154+
lock.Unlock()
155+
for _, callback := range callbacks {
129156
callback()
130157
}
131158

routers/web/user/notification.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func Notifications(c *context.Context) {
5050
return
5151
}
5252
if c.QueryBool("div-only") {
53+
c.Data["SequenceNumber"] = c.Query("sequence-number")
5354
c.HTML(http.StatusOK, tplNotificationDiv)
5455
return
5556
}
@@ -175,6 +176,7 @@ func NotificationStatusPost(c *context.Context) {
175176
return
176177
}
177178
c.Data["Link"] = setting.AppURL + "notifications"
179+
c.Data["SequenceNumber"] = c.Req.PostFormValue("sequence-number")
178180

179181
c.HTML(http.StatusOK, tplNotificationDiv)
180182
}

templates/user/notification/notification_div.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="page-content user notification" id="notification_div" data-params="{{.Page.GetParams}}">
1+
<div class="page-content user notification" id="notification_div" data-params="{{.Page.GetParams}}" data-sequence-number="{{.SequenceNumber}}">
22
<div class="ui container">
33
<h1 class="ui dividing header">{{.i18n.Tr "notification.notifications"}}</h1>
44
<div class="ui top attached tabular menu">

web_src/js/features/notification.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const {AppSubUrl, csrf, NotificationSettings} = window.config;
22

3+
let notificationSequenceNumber = 0;
4+
35
export function initNotificationsTable() {
46
$('#notification_table .button').on('click', async function () {
57
const data = await updateNotification(
@@ -10,8 +12,10 @@ export function initNotificationsTable() {
1012
$(this).data('notification-id'),
1113
);
1214

13-
$('#notification_div').replaceWith(data);
14-
initNotificationsTable();
15+
if ($(data).data('sequence-number') === notificationSequenceNumber) {
16+
$('#notification_div').replaceWith(data);
17+
initNotificationsTable();
18+
}
1519
await updateNotificationCount();
1620

1721
return false;
@@ -139,10 +143,13 @@ async function updateNotificationTable() {
139143
url: `${AppSubUrl}/notifications?${notificationDiv.data('params')}`,
140144
data: {
141145
'div-only': true,
146+
'sequence-number': ++notificationSequenceNumber,
142147
}
143148
});
144-
notificationDiv.replaceWith(data);
145-
initNotificationsTable();
149+
if ($(data).data('sequence-number') === notificationSequenceNumber) {
150+
notificationDiv.replaceWith(data);
151+
initNotificationsTable();
152+
}
146153
}
147154
}
148155

@@ -182,6 +189,7 @@ async function updateNotification(url, status, page, q, notificationID) {
182189
page,
183190
q,
184191
noredirect: true,
192+
'sequence-number': ++notificationSequenceNumber,
185193
},
186194
});
187195
}

0 commit comments

Comments
 (0)