Commit Graph

75 Commits

Author SHA1 Message Date
Qi Xiao
4afbb71c07 Move pkg/testutil/must.go to a new pkg/must. 2022-06-20 20:29:14 +01:00
Qi Xiao
a3cc6a44f0 pkg/daemon: Fix a comment. 2022-06-19 19:06:24 +01:00
Qi Xiao
01756ef57a pkg/daemon: Ignore error when closing connections on shutdown.
The logs are not useful anyway since the reason is invariably that the client
has already closed the connection.

Moreover, timing in the shutdown sequence causes fluctuation in test coverage;
removing this log eliminates the fluctuation.
2022-06-14 21:01:50 +01:00
Qi Xiao
dd3950cec0 Use the new testutil.Set in more places. 2022-04-11 21:55:59 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
f7cb556d9b Require Go 1.18.
- Run "go fix" to remove legacy build tags

- Use staticcheck@master until it has a release that supports Go 1.18

- Turn off autocrlf for Windows tasks
2022-03-20 15:28:23 +00:00
Qi Xiao
d3a31ae193 Revamp command-line flag doc.
- Document all flags, and remove doc for removed flags.

- Update in-code flag descriptions to be more consistent with the markdown doc.
2022-03-03 00:41:39 +00:00
Qi Xiao
33a04f8dc1 Revamp flag handling in pkg/prog.
Instead of putting all possible flags in prog.Flags, flags are now registered by
the individual subprograms. The 3 flags -sock, -db and -json are shared by
multiple subprograms and still handled by the prog package.

This new design allows separating the support for -cpuprofile into a separate
subprogram, which is no longer included by the default entry point, making the
binary slightly smaller. A new entrypoint "withpprof" is created.

Also include the LSP subprogram in the nodaemon entry point.
2022-02-05 14:52:29 +00:00
moko256
f4bc35dbd0 Use src.elv.sh/pkg/rpc instead of net/rpc. 2022-01-30 22:49:54 +00:00
Qi Xiao
74003a7f56 pkg/daemon: Always quit after receiving a signal.
The current code will busy-loop after receiving a signal until the listener
errors or all existing connection returns.
2021-10-23 18:39:55 +01:00
Qi Xiao
5b490475e7 pkg/testutil: ScaledMs -> Scaled, takes a time.Duration instead. 2021-10-05 01:02:54 +01:00
Qi Xiao
bfb9986339 pkg/daemon: Fix activate_unix_test.go. 2021-10-02 19:04:36 +01:00
Qi Xiao
eadb0c3283 pkg/daemon: Only test the code to interrupt old daemon on UNIX.
Windows does not support sending interrupts to processes without
consoles.
2021-10-02 19:02:28 +01:00
Qi Xiao
4f63beab17 pkg/daemon: Let killDaemon wait until the socket file is removed.
There is a race condition where the old daemon may remove the socket file
created by the new daemon.
2021-10-02 18:41:50 +01:00
Qi Xiao
56b2598284 pkg/daemon: Add util for testing the termination of server. 2021-10-02 16:02:05 +01:00
Qi Xiao
b801a99d2a pkg/daemon: Test Activate killing outdated daemon. 2021-10-02 15:47:18 +01:00
Qi Xiao
93f530b39d pkg/daemon: Fix test when run as root. 2021-10-02 01:29:17 +01:00
Qi Xiao
bd285bd25c pkg/daemon: Slightly improve the coverage of activate.go. 2021-10-02 01:21:21 +01:00
Qi Xiao
101576471b pkg/daemon: Fix the handling of hanging sockets.
Also enable the test.

The implementation incorrectly assumed that trying to connect to a hanging
socket will return rpc.ErrShutdown; this is not actually the case.

Also change error wrapping in activate.go to use %w instead of %v to preserve
the wrapped error.
2021-10-01 23:56:57 +01:00
Qi Xiao
821a204fef pkg/daemon: Test that Activate can remove hanging socket.
The test is currently skipped since the corresponding behavior has not been
implemented correctly.
2021-10-01 22:19:23 +01:00
Qi Xiao
fe0a8602d3 pkg/daemon: Test daemon spawning.
Also do some minor cleanup.
2021-10-01 21:54:15 +01:00
Qi Xiao
6e4296db2b Make TestActivate_FailsIfCannotStatSock work on Windows. 2021-10-01 19:14:50 +01:00
Qi Xiao
e60fd50737 Only skip the test on Windows. 2021-10-01 00:38:06 +01:00
Qi Xiao
7f8ab450a5 Disable test that may have inadvertently triggered daemon spawning. 2021-10-01 00:32:32 +01:00
Qi Xiao
09e5ffe9d9 pkg/daemon: Improve the coverage of activate.go slightly.
Also remove an unused code branch.
2021-10-01 00:03:22 +01:00
Qi Xiao
7995cc5f6f pkg/daemon: Add basic test for Activate. 2021-09-30 23:45:38 +01:00
Qi Xiao
8e117a2875 Merge pkg/daemon/client into pkg/daemon.
Also merge and rename files to make the client/server separation clearer.
2021-09-30 23:37:36 +01:00
Qi Xiao
025728b35d pkg/daemon: Don't test any system signal behavior on Windows.
(*os.Process).Signal doesn't support sending SIGINT on Windows either.
2021-09-29 23:50:45 +01:00
Qi Xiao
fdd65538c6 pkg/daemon: Don't test SIGTERM on Windows.
Also don't block test indefinitely if server doesn't terminate.
2021-09-29 23:44:34 +01:00
Qi Xiao
3eedcf3c85 pkg/daemon: Increase coverage of serve.go. 2021-09-29 23:30:13 +01:00
Qi Xiao
cff34107da pkg/daemon: Rewrite the main loop and make it easier to test. 2021-09-23 20:54:12 +01:00
Qi Xiao
9344aa9659 pkg/daemon/daemon_test.go: Disable TestProgram_StillServesIfCannotOpenDB now. 2021-09-15 21:37:28 +01:00
Qi Xiao
e046315d28 pkg/daemon/daemon_test.go: Return more detailed error from startClient. 2021-09-15 21:31:51 +01:00
Qi Xiao
7d5175e082 pkg/daemon: In tests, print error to stdout if server fails to start. 2021-09-15 21:12:26 +01:00
Qi Xiao
11d36554fe pkg/daemon: Test that the daemon still serves if failing to open DB.
Also change Serve to not use the default server of net/rpc (which made it
impossible to call Serve multiple times), and return the exit code instead of
using os.Exit.

Also change service.Version to always succeed; this is necessary since
client.Activate uses this method to determine connection health.
2021-09-15 20:59:37 +01:00
Qi Xiao
73c269b98f pkg/daemon: Do not use client.Activate in test to connect to server.
client.Active will try to spawn a new server if it cannot connect; this
is not desirable.
2021-09-12 23:53:08 +01:00
Qi Xiao
aa7e958704 pkg/daemon: Terminate test correctly if server did not come up. 2021-09-12 23:45:23 +01:00
Qi Xiao
3bd132b53e pkg/daemon: Rewrite test to exercise the Program. 2021-09-12 23:18:37 +01:00
Qi Xiao
e0b824bbdf Improve coverage for "no suitable subprogram" error. 2021-09-12 14:23:29 +01:00
Qi Xiao
b6d69d0b30 pkg/prog/progtest: Rewrite the progtest API.
The progtest package now provides a declarative framework, modelled after
pkg/eval/evaltest. Tests that use progtest are now much more concise.
2021-09-12 14:06:05 +01:00
Qi Xiao
be3431bbbf pkg/prog: Simplify the Program interface.
Instead of a separate ShouldRun method, use a special error value to signify
that a Program should not be run.
2021-09-12 00:40:35 +01:00
Qi Xiao
05a3251cd8 pkg/daemon: Use UNIX socket on Windows.
Windows 10 has supported UNIX sockets for a pretty long time
(https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/).

Interestingly, os.Stat calls on UNIX socket files fail on Windows; only
os.Lstat calls work.
2021-09-11 22:05:06 +01:00
Qi Xiao
9076934395 Remove most uses of the ioutil package.
https://golang.org/doc/go1.16#ioutil
2021-08-23 00:36:26 +01:00
Qi Xiao
7fa09ac1d3 Use buffered channels with signal.Notify.
Both places act on the first signal received, so a buffer size of 1 is
sufficient.
2021-08-23 00:22:11 +01:00
Qi Xiao
d0be34c227 Run gofmt with Go 1.17.
This has created a lot of //go:build lines.
2021-08-23 00:19:49 +01:00
Qi Xiao
e9d328aa16 Make use of (*testing.T).Cleanup for test cleanups.
This allows turning the following pattern in tests:

  value, cleanup := setupSomething()
  defer cleanup()

into the following:

  value := setupSomething(t)
2021-08-06 23:21:23 +01:00
Qi Xiao
d92c4bc08a Refactor shell and daemon initialization code.
In particular, the code for retrieving file paths needed by the runtime is
simplified a lot, and the paths only needed for the storage daemon is cleanly
separated from other paths.
2021-06-28 20:02:38 +01:00
Qi Xiao
8c97ed2184 pkg/daemon: Don't depend on net.ErrClosed.
It was added in Go 1.16, but we still support building with Go 1.15.
2021-06-28 00:13:14 +01:00
Qi Xiao
3b390f0792 pkg/daemon: Be slightly less chatty in logs. 2021-06-27 23:57:01 +01:00
Qi Xiao
42867d56ba Remove the -bin flag.
Always determine it with os.Executable() instead.
2021-06-27 23:12:09 +01:00