mirror of
https://github.com/rclone/rclone.git
synced 2026-10-09 14:39:28 -04:00
Before this change the parent process kept the remote control and
metrics servers it started in initConfig listening, so the daemon child
could not bind the same addresses and exited.
After this change the parent shuts those servers down just before
daemonizing, and the child starts them as usual.
(cherry picked from commit 4532a88838)
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/rclone/rclone/fs/rc"
|
|
"github.com/rclone/rclone/fs/rc/rcserver"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func freeAddr(t *testing.T) string {
|
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
|
require.NoError(t, err)
|
|
addr := l.Addr().String()
|
|
require.NoError(t, l.Close())
|
|
return addr
|
|
}
|
|
|
|
func TestStopRemoteControl(t *testing.T) {
|
|
ctx := context.Background()
|
|
rcAddr, metricsAddr := freeAddr(t), freeAddr(t)
|
|
opt := rc.Opt
|
|
opt.Enabled = true
|
|
opt.HTTP.ListenAddr = []string{rcAddr}
|
|
opt.MetricsHTTP.ListenAddr = []string{metricsAddr}
|
|
|
|
var err error
|
|
rcServer, err = rcserver.Start(ctx, &opt)
|
|
require.NoError(t, err)
|
|
metricsServer, err = rcserver.MetricsStart(ctx, &opt)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, rcServer)
|
|
require.NotNil(t, metricsServer)
|
|
|
|
for _, addr := range []string{rcAddr, metricsAddr} {
|
|
_, err := net.Listen("tcp", addr)
|
|
require.Error(t, err, "%s should be in use while the servers run", addr)
|
|
}
|
|
|
|
StopRemoteControl()
|
|
assert.Nil(t, rcServer)
|
|
assert.Nil(t, metricsServer)
|
|
|
|
for _, addr := range []string{rcAddr, metricsAddr} {
|
|
l, err := net.Listen("tcp", addr)
|
|
require.NoError(t, err, "%s should be free after StopRemoteControl", addr)
|
|
require.NoError(t, l.Close())
|
|
}
|
|
}
|