Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
users-mgmt-test: fix possible race condition
The clustermesh users management test was affected by a possible race condition due to the fact that the configuration file was overwritten with 'os.WriteFile'. Since this method first opens the file truncating it and then writes the desired content, we could be notified and read the file in that time interval, hence observing an empty file. This caused all users to be first deleted and then recreated, leading the test to fail. To avoid this issue, we now first write a different file, and then rename it. In this way, the update operation is atomic, and we always observe the correct file content. Failing test output: level=info msg=Invoked duration="34.8µs" function="github.com/cilium/cilium/clustermesh-apiserver.registerUsersManager (users_mgmt.go:69)" subsys=hive level=info msg=Starting subsys=hive level=info msg="Starting managing etcd users based on configuration" file-path=/tmp/clustermesh-config159493219/users.yaml subsys=clustermesh-apiserver level=info msg="Start hook executed" duration="115.098µs" function="*main.usersManager.Start" subsys=hive level=info msg="User successfully configured" subsys=clustermesh-apiserver user=foo level=info msg="User successfully configured" subsys=clustermesh-apiserver user=bar level=info msg="User successfully configured" subsys=clustermesh-apiserver user=qux level=info msg="User successfully removed" subsys=clustermesh-apiserver user=foo level=info msg="User successfully removed" subsys=clustermesh-apiserver user=bar level=info msg="User successfully removed" subsys=clustermesh-apiserver user=qux level=info msg="User successfully configured" subsys=clustermesh-apiserver user=baz level=info msg="User successfully configured" subsys=clustermesh-apiserver user=foo level=info msg="User successfully configured" subsys=clustermesh-apiserver user=qux users_mgmt_test.go:123: Error Trace: /home/runner/work/cilium/cilium/clustermesh-apiserver/users_mgmt_test.go:123 Error: "map[baz:r3 foo:r1 qux:r4]" should have 2 item(s), but has 3 Test: TestUsersManagement level=info msg=Stopping subsys=hive level=info msg="Stopping managing etcd users based on configuration" file-path=/tmp/clustermesh-config159493219/users.yaml subsys=clustermesh-apiserver level=info msg=Closing subsys=clustermesh-apiserver level=info msg="Stop hook executed" duration="27.8µs" function="*main.usersManager.Stop" subsys=hive Fixes: 60f94e4 ("clustermesh-apiserver: implement users management for remote clusters") Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
- Loading branch information