Maciej Borzecki
4484bbe60b
desktop/notification/notificationtest: fix data races
...
Fix data races identified by go test -race caused by manipulation of fields of
an exported dbus object.
```
==================
WARNING: DATA RACE
Read at 0x00c0003f0fd0 by goroutine 191:
github.com/godbus/dbus.(*Conn).sendError()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:482 +0x6cf
github.com/godbus/dbus.(*Conn).handleCall()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/export.go:155 +0x9dc
github.com/godbus/dbus.(*Conn).inWorker.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x44
Previous write at 0x00c0003f0fd0 by goroutine 182:
github.com/snapcore/snapd/desktop/notification_test.(*gtkSuite).TestCloseNotificationError()
/home/maciek/work/canonical/snapd/desktop/notification/gtk_test.go:108 +0x224
runtime.call16()
/usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
reflect.Value.Call()
/usr/lib/go/src/reflect/value.go:380 +0xb5
gopkg.in/check%2ev1.(*suiteRunner).forkTest.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:775 +0x9c5
gopkg.in/check%2ev1.(*suiteRunner).forkCall.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:669 +0xe9
Goroutine 191 (running) created at:
github.com/godbus/dbus.(*Conn).inWorker()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x346
github.com/godbus/dbus.(*Conn).Auth.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/auth.go:118 +0x33
Goroutine 182 (running) created at:
gopkg.in/check%2ev1.(*suiteRunner).forkCall()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:666 +0x5ba
gopkg.in/check%2ev1.(*suiteRunner).forkTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:757 +0x155
gopkg.in/check%2ev1.(*suiteRunner).runTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:812 +0x419
gopkg.in/check%2ev1.(*suiteRunner).run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:618 +0x3c6
gopkg.in/check%2ev1.Run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:92 +0x44
gopkg.in/check%2ev1.RunAll()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:84 +0x124
gopkg.in/check%2ev1.TestingT()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:72 +0x5d3
github.com/snapcore/snapd/desktop/notification_test.Test()
/home/maciek/work/canonical/snapd/desktop/notification/notify_test.go:30 +0x26
testing.tRunner()
/usr/lib/go/src/testing/testing.go:1689 +0x21e
testing.(*T).Run.gowrap1()
/usr/lib/go/src/testing/testing.go:1742 +0x44
==================
```
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com >
2024-04-16 12:00:37 +02:00
Maciej Borzecki
b785a4410e
desktop/notification/notificationtest: fix deadlock in CloseNotification
...
The test code takes the server lock for the whole duration of CloseNotification,
what causes a deadlock due to a call to Close()
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com >
2024-04-08 14:09:11 +02:00
Maciej Borzecki
8e088a787e
desktop/portal: fix data race in unit tests
...
go test -race found a data race accessing fields of a mock service running
asynchronously in a goroutine and the test
```
==================
WARNING: DATA RACE
Read at 0x00c00021a078 by goroutine 23:
github.com/snapcore/snapd/desktop/portal_test.(*documentPortalSuite).TestGetMountPointResponseError()
/home/maciek/work/canonical/snapd/desktop/portal/document_test.go:124 +0x531
runtime.call16()
/usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
reflect.Value.Call()
/usr/lib/go/src/reflect/value.go:380 +0xb5
gopkg.in/check%2ev1.(*suiteRunner).forkTest.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:775 +0x9c5
gopkg.in/check%2ev1.(*suiteRunner).forkCall.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:669 +0xe9
Previous write at 0x00c00021a078 by goroutine 26:
github.com/snapcore/snapd/desktop/portal_test.(*fakeDocumentPortal).GetMountPoint()
/home/maciek/work/canonical/snapd/desktop/portal/document_test.go:146 +0x10e
runtime.call16()
/usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
reflect.Value.Call()
/usr/lib/go/src/reflect/value.go:380 +0xb5
github.com/godbus/dbus.exportedMethod.Call()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/default_handler.go:128 +0x219
github.com/godbus/dbus.(*exportedMethod).Call()
<autogenerated>:1 +0x84
github.com/godbus/dbus.(*Conn).handleCall()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/export.go:153 +0x591
github.com/godbus/dbus.(*Conn).inWorker.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x44
Goroutine 23 (running) created at:
gopkg.in/check%2ev1.(*suiteRunner).forkCall()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:666 +0x5ba
gopkg.in/check%2ev1.(*suiteRunner).forkTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:757 +0x155
gopkg.in/check%2ev1.(*suiteRunner).runTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:812 +0x419
gopkg.in/check%2ev1.(*suiteRunner).run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:618 +0x3c6
gopkg.in/check%2ev1.Run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:92 +0x44
gopkg.in/check%2ev1.RunAll()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:84 +0x124
gopkg.in/check%2ev1.TestingT()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:72 +0x5d3
github.com/snapcore/snapd/desktop/portal_test.Test()
/home/maciek/work/canonical/snapd/desktop/portal/launcher_test.go:50 +0x26
testing.tRunner()
/usr/lib/go/src/testing/testing.go:1689 +0x21e
testing.(*T).Run.gowrap1()
/usr/lib/go/src/testing/testing.go:1742 +0x44
Goroutine 26 (finished) created at:
github.com/godbus/dbus.(*Conn).inWorker()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x346
github.com/godbus/dbus.(*Conn).Auth.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/auth.go:118 +0x33
==================
==================
WARNING: DATA RACE
Read at 0x00c00018ebc0 by goroutine 23:
reflect.Value.String()
/usr/lib/go/src/reflect/value.go:2654 +0x1bed
reflect.deepValueEqual()
/usr/lib/go/src/reflect/deepequal.go:165 +0x1c54
reflect.deepValueEqual()
/usr/lib/go/src/reflect/deepequal.go:113 +0x1f69
reflect.DeepEqual()
/usr/lib/go/src/reflect/deepequal.go:238 +0x244
gopkg.in/check%2ev1.(*deepEqualsChecker).Check()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/checkers.go:269 +0x92
gopkg.in/check%2ev1.(*C).internalCheck()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/helpers.go:216 +0x53e
gopkg.in/check%2ev1.(*C).Check()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/helpers.go:162 +0x664
github.com/snapcore/snapd/desktop/portal_test.(*documentPortalSuite).TestGetMountPointResponseError()
/home/maciek/work/canonical/snapd/desktop/portal/document_test.go:124 +0x3f5
runtime.call16()
/usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
reflect.Value.Call()
/usr/lib/go/src/reflect/value.go:380 +0xb5
gopkg.in/check%2ev1.(*suiteRunner).forkTest.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:775 +0x9c5
gopkg.in/check%2ev1.(*suiteRunner).forkCall.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:669 +0xe9
Previous write at 0x00c00018ebc0 by goroutine 26:
github.com/snapcore/snapd/desktop/portal_test.(*fakeDocumentPortal).GetMountPoint()
/home/maciek/work/canonical/snapd/desktop/portal/document_test.go:146 +0xb6
runtime.call16()
/usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
reflect.Value.Call()
/usr/lib/go/src/reflect/value.go:380 +0xb5
github.com/godbus/dbus.exportedMethod.Call()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/default_handler.go:128 +0x219
github.com/godbus/dbus.(*exportedMethod).Call()
<autogenerated>:1 +0x84
github.com/godbus/dbus.(*Conn).handleCall()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/export.go:153 +0x591
github.com/godbus/dbus.(*Conn).inWorker.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x44
Goroutine 23 (running) created at:
gopkg.in/check%2ev1.(*suiteRunner).forkCall()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:666 +0x5ba
gopkg.in/check%2ev1.(*suiteRunner).forkTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:757 +0x155
gopkg.in/check%2ev1.(*suiteRunner).runTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:812 +0x419
gopkg.in/check%2ev1.(*suiteRunner).run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:618 +0x3c6
gopkg.in/check%2ev1.Run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:92 +0x44
gopkg.in/check%2ev1.RunAll()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:84 +0x124
gopkg.in/check%2ev1.TestingT()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:72 +0x5d3
github.com/snapcore/snapd/desktop/portal_test.Test()
/home/maciek/work/canonical/snapd/desktop/portal/launcher_test.go:50 +0x26
testing.tRunner()
/usr/lib/go/src/testing/testing.go:1689 +0x21e
testing.(*T).Run.gowrap1()
/usr/lib/go/src/testing/testing.go:1742 +0x44
Goroutine 26 (finished) created at:
github.com/godbus/dbus.(*Conn).inWorker()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x346
github.com/godbus/dbus.(*Conn).Auth.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/auth.go:118 +0x33
==================
```
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com >
2024-04-08 09:49:32 +02:00
Maciej Borzecki
96b8f4a156
desktop/notification/notificationtest: fix data race
...
Use sever mutex to protect access to err field. Running `go test -race` fails
with the following error:
==================
WARNING: DATA RACE
Read at 0x00c0003b72f8 by goroutine 468:
github.com/snapcore/snapd/desktop/notification/notificationtest.fdoApi.Notify()
/home/maciek/work/canonical/snapd/desktop/notification/notificationtest/fdo.go:149 +0x9c
runtime.call128()
/usr/lib/go/src/runtime/asm_amd64.s:773 +0x57
reflect.Value.Call()
/usr/lib/go/src/reflect/value.go:380 +0xb5
github.com/godbus/dbus.exportedMethod.Call()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/default_handler.go:128 +0x219
github.com/godbus/dbus.(*exportedMethod).Call()
<autogenerated>:1 +0x84
github.com/godbus/dbus.(*Conn).handleCall()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/export.go:153 +0x591
github.com/godbus/dbus.(*Conn).inWorker.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x44
Previous write at 0x00c0003b72f8 by goroutine 453:
github.com/snapcore/snapd/desktop/notification/notificationtest.(*FdoServer).SetError()
/home/maciek/work/canonical/snapd/desktop/notification/notificationtest/fdo.go:97 +0x99
github.com/snapcore/snapd/usersession/agent_test.(*restSuite).TestPostPendingRefreshNotificationNotificationServerFailure()
/home/maciek/work/canonical/snapd/usersession/agent/rest_api_test.go:855 +0xed
runtime.call16()
/usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
reflect.Value.Call()
/usr/lib/go/src/reflect/value.go:380 +0xb5
gopkg.in/check%2ev1.(*suiteRunner).forkTest.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:775 +0x9c5
gopkg.in/check%2ev1.(*suiteRunner).forkCall.func1()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:669 +0xe9
Goroutine 468 (running) created at:
github.com/godbus/dbus.(*Conn).inWorker()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/conn.go:334 +0x346
github.com/godbus/dbus.(*Conn).Auth.gowrap1()
/home/maciek/work/canonical/snapd/vendor/github.com/godbus/dbus/auth.go:118 +0x33
Goroutine 453 (running) created at:
gopkg.in/check%2ev1.(*suiteRunner).forkCall()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:666 +0x5ba
gopkg.in/check%2ev1.(*suiteRunner).forkTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:757 +0x155
gopkg.in/check%2ev1.(*suiteRunner).runTest()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:812 +0x419
gopkg.in/check%2ev1.(*suiteRunner).run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:618 +0x3c6
gopkg.in/check%2ev1.Run()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:92 +0x44
gopkg.in/check%2ev1.RunAll()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:84 +0x124
gopkg.in/check%2ev1.TestingT()
/home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:72 +0x5d3
github.com/snapcore/snapd/usersession/agent_test.Test()
/home/maciek/work/canonical/snapd/usersession/agent/session_agent_test.go:44 +0x26
testing.tRunner()
/usr/lib/go/src/testing/testing.go:1689 +0x21e
testing.(*T).Run.gowrap1()
/usr/lib/go/src/testing/testing.go:1742 +0x44
==================
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com >
2024-04-08 09:46:50 +02:00
Miguel Pires
29c9752d66
many: s/ioutil.WriteFile/os.WriteFile ( #13217 )
...
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.
Signed-off-by: Miguel Pires <miguel.pires@canonical.com >
2023-09-26 11:38:46 +01:00
James Henstridge
1a31076a55
desktop: adjust error message and comments based on mvo's review
2023-09-06 16:44:05 +02:00
James Henstridge
de13b0d313
desktop/desktopentry: have %u and %U expand to regular file paths if possible
...
This matches glib's behaviour, and the specification which reads "Local
files may either be passed as file: URLs or as file path".
2023-09-06 16:44:05 +02:00
James Henstridge
39560a0218
desktopentry/desktop: add some tests for macros within quoted string undefined behaviour
2023-09-06 16:44:05 +02:00
James Henstridge
1a1cc1c680
desktop/desktopentry: tweak some more expandExec tests
2023-09-06 16:44:05 +02:00
James Henstridge
a39ba05166
desktop/desktopentry: update comments and tests based on review
2023-09-06 16:44:05 +02:00
James Henstridge
4850a32d26
desktop/desktopentry: update comment
2023-09-06 16:44:05 +02:00
James Henstridge
dea4dea1fd
desktop/desktopentry: add more tests for file URI checks, and special characters within file paths
2023-09-06 16:44:05 +02:00
James Henstridge
dfece4eee1
desktop/desktopentry: add a test for the "is not an absolute URI" case
2023-09-06 16:44:05 +02:00
James Henstridge
9760176d8d
desktop/desktopentry: add doc comments, and test the unknownGroup parse state
2023-09-06 16:44:05 +02:00
James Henstridge
b11737bb66
desktop/desktopentry: rename Load to Read
2023-09-06 16:44:05 +02:00
James Henstridge
6b5587c606
desktop/desktopentry: ignore whitespace surrounding equals sign
...
The glib implementation only ignores ASCII whitespace here, so we do the
same.
2023-09-06 16:44:05 +02:00
James Henstridge
7463ec0bfd
desktop/desktopentry: fix expansion of 2+ files/uris, and add more tests
2023-09-06 16:44:05 +02:00
James Henstridge
530d715c2b
usersession: port privileged_desktop_launcher code over to desktopentry package
2023-09-06 16:44:05 +02:00
James Henstridge
da2a7b4e0f
desktop: add a test for the top level Load function
2023-09-06 16:44:05 +02:00
James Henstridge
17091d4171
desktop: add code to expand an exec line from a desktop file
...
The code in glib was used as a reference where the spec was ambiguous.
2023-09-06 16:44:05 +02:00
James Henstridge
6db3b59734
desktop: extract a basic desktop entry parser from desktop-launch and autostart code
2023-09-06 16:44:05 +02:00
Michael Vogt
46ef068423
many: replace use of "sanity" with more inclusive naming
...
This commit replaces the use of "sanity" with more inclusive
naming. When "sanity" is used in a more general sense either
"validity" or "quick" is used.
2022-03-16 09:10:59 +01:00
Miguel Pires
615da7771d
many: fix failing golangci checks
...
* Group 3rd party imports
* Remove unused vars
* Move var only used in tests into test
* Add 'nolint' to ignore warning on unused iotas (might've been
left to improve readability).
2022-02-09 10:12:09 +00:00
Paweł Stołowski
4111c86b77
Fix locking. Remove updates of lookup maps from CloseNotification method
...
and rely on processNotificationClosed instead.
2021-11-04 11:56:31 +01:00
Paweł Stołowski
7846de9b11
Handle observing of notifications.
2021-11-04 11:56:31 +01:00