Commit Graph

50 Commits

Author SHA1 Message Date
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
Qi Xiao
6e75f3468c Move API of pkg/store into pkg/storedefs.
This makes the nodaemon entrypoint not depend on boltdb at all, reducing its
size by 100KB (on darwin-arm64).
2021-06-19 01:54:00 +01:00
Qi Xiao
d6464280f2 Remove direct dependency of pkg/shell on the daemon implementation.
The dependency is injected via a field in shell.Program.

Also add an alternative entrypoint, cmd/nodaemon/elvish, which does not include
the daemon server or client.
2021-06-19 01:43:30 +01:00
Qi Xiao
27eec7c8ee Reorganize the daemon module.
* Move client, spawning and activation code into pkg/daemon/client.

* Move API types into pkg/daemon/daemondefs.
2021-06-19 01:06:11 +01:00
Kurtis Rader
60bcb27e16 Remove obsolete store API method
While working on issue #568 to add a `&dedup` option to the
`edit:command-history` command I noticed that the `store.Cmd.Cmds()`
method should be removed.
2021-05-30 00:33:37 +01:00
Qi Xiao
72fc2dbe4a Copy and trim down the net/rpc package.
In particular, the dependency on net/http is removed, which removes a
bunch of transitive dependencies.
2021-01-30 23:56:58 +00:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
327561ed0a pkg/daemon: Move the opening of stdin for the daemon to spawn.go. 2021-01-17 00:12:36 +00:00
Kurtis Rader
d241243fdf Ensure the daemon doesn't have fds open on the tty
The Elvish daemon should not inherit file descriptors open on the tty.
Make the daemon's stdin open on the null device and its stdout/stderr
open on a predictable file.

Fixes #1191
2021-01-16 23:18:38 +00:00
Qi Xiao
11898f763a pkg/util: Break into fsutil/ and logutil/. 2020-09-03 05:27:18 +01:00
Qi Xiao
48919bcb24 pkg/: Move test utilities from util/ to testutil/. 2020-09-03 04:55:16 +01:00
Kurtis Rader
b5b3a0d607 go vet cleanup
Most of the code uses keyed fields in composite literals; i.e., struct
literals. However, running `go vet ./...` reports a few places that use
anonymous fields. This modifies those composite literals to use keyed
fields. This does make the code a bit more verbose without reducing
the likelihood of a bug. But it does make the code more consistent, use
best practices, and make it easier to notice if a potential problem is
introduced when running `go vet ./...` since that command now produces
no diagnostic output.

I considered adding a `make vet` target that explicitly ran

    go vet -composites=false ./...

I decided not to do that since consistently using keyed composite literals
is preferable to having a mix of keyed and unkeyed composite literals.

This also removes the unused `ExampleLoop` function which causes this
`go vet` warning:

    pkg/cli/loop_test.go:130:1: ExampleLoop refers to unknown identifier: Loop
2020-09-03 04:24:06 +01:00
Qi Xiao
928949077b pkg/prog: Move all Program implementations into own packages.
This fixes #985.
2020-04-25 00:12:18 +01:00
Qi Xiao
f55bc315c9 pkg/daemon: Run tests from pkg/store/storetest.
This addresses #944.

Also fix a bug with DelSharedVar that was found by the new test.
2020-04-06 00:48:48 +01:00
Qi Xiao
b93ef8aa4a pkg/daemon: Add more tests, and remove unused code.
This addresses #944.
2020-04-06 00:19:03 +01:00
Qi Xiao
04e296bb10 pkg/program/daemon: Merge with pkg/daemon. 2020-04-04 16:50:25 +01:00
Qi Xiao
770fd8e6c4 Scale all test timeouts with $ELVISH_TEST_TIME_SCALE. 2020-04-03 22:12:20 +01:00
Qi Xiao
f6d036cb48 pkg/daemon: Fix the CmdsWithSeq client. 2019-12-28 02:01:39 +00:00
Qi Xiao
95b9ba91d8 pkg/{store,daemon}: Introduce a new CmdsWithSeq method. 2019-12-27 11:48:34 +00:00
Qi Xiao
c2d82cafe5 pkg/store: Introduce a Cmd type for command history entries.
This type supersededs pkg/cli/histutil.Entry.
2019-12-27 11:13:33 +00:00
Qi Xiao
6b876e559d pkg/store: Interface -> Store. 2019-12-26 18:09:26 +00:00
Qi Xiao
cbe0e3e7e7 Merge pkg/store/storedefs into pkg/store. 2019-12-26 18:05:13 +00:00
Qi Xiao
e6497a87cc pkg/daemon: Move Version back to the daemon package. 2019-12-26 17:31:15 +00:00
Qi Xiao
8ed2c0c461 pkg/daemon: Move API types into an internal package. 2019-12-26 17:26:59 +00:00
Qi Xiao
012b779ca7 pkg/daemon: Make Client an interface. 2019-12-26 17:23:18 +00:00
Qi Xiao
e45fdf7228 Move all libraries to new pkg/. 2019-12-23 20:00:59 +00:00