commit 75d20bcd792dbee6682b653497ef542d582cfd28
parent f728a1471e9389fe2ba31192f295e4224b1f2e3b
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sun, 7 Jan 2024 12:16:16 +0900
delete unnecessary test code
Diffstat:
2 files changed, 21 insertions(+), 53 deletions(-)
diff --git a/client/client.go b/client/client.go
@@ -241,7 +241,7 @@ func (c *Client) runMultiplexer(ctx context.Context, tmsgc chan<- lib9p.Msg, rms
return
case r := <-txc:
if _, ok := rPool.lookup(r.tag); ok {
- r.errc <- fmt.Errorf("mux: duplicate tag: %d", r.tag)
+ r.errc <- fmt.Errorf("mux: %w: %d", lib9p.ErrDupTag, r.tag)
continue
}
rPool.add(r)
@@ -288,7 +288,7 @@ func (c *Client) Version(tag uint16, msize uint32, version string) (uint32, stri
tmsg := &lib9p.TVersion{Tag: tag, Msize: msize, Version: version}
rmsg, err := c.transact(tmsg)
if err != nil {
- return 0, "", fmt.Errorf("transact: %v", err)
+ return 0, "", fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RVersion:
@@ -304,7 +304,7 @@ func (c *Client) Auth(tag uint16, afid uint32, uname, aname string) (lib9p.Qid,
tmsg := &lib9p.TAuth{Tag: tag, Afid: afid, Uname: uname}
rmsg, err := c.transact(tmsg)
if err != nil {
- return lib9p.Qid{}, fmt.Errorf("transact: %v", err)
+ return lib9p.Qid{}, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RAuth:
@@ -320,7 +320,7 @@ func (c *Client) Attach(tag uint16, fid, afid uint32, uname, aname string) (lib9
tmsg := &lib9p.TAttach{Tag: tag, Fid: fid, Afid: afid, Uname: uname, Aname: aname}
rmsg, err := c.transact(tmsg)
if err != nil {
- return lib9p.Qid{}, fmt.Errorf("transact: %v", err)
+ return lib9p.Qid{}, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RAttach:
@@ -336,7 +336,7 @@ func (c *Client) Flush(tag, oldtag uint16) error {
tmsg := &lib9p.TFlush{Tag: tag, Oldtag: oldtag}
rmsg, err := c.transact(tmsg)
if err != nil {
- return fmt.Errorf("transact: %v", err)
+ return fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RFlush:
@@ -351,7 +351,7 @@ func (c *Client) Walk(tag uint16, fid, newfid uint32, wnames []string) (wqid []l
tmsg := &lib9p.TWalk{Tag: tag, Fid: fid, Newfid: newfid, Wnames: wnames}
rmsg, err := c.transact(tmsg)
if err != nil {
- return nil, fmt.Errorf("transact: %v", err)
+ return nil, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RWalk:
@@ -366,7 +366,7 @@ func (c *Client) Open(tag uint16, fid uint32, mode lib9p.OpenMode) (qid lib9p.Qi
tmsg := &lib9p.TOpen{Tag: tag, Fid: fid, Mode: mode}
rmsg, err := c.transact(tmsg)
if err != nil {
- return lib9p.Qid{}, 0, fmt.Errorf("transact: %v", err)
+ return lib9p.Qid{}, 0, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.ROpen:
@@ -381,7 +381,7 @@ func (c *Client) Create(tag uint16, fid uint32, name string, perm lib9p.FileMode
tmsg := &lib9p.TCreate{Tag: tag, Fid: fid, Name: name, Perm: perm, Mode: mode}
rmsg, err := c.transact(tmsg)
if err != nil {
- return lib9p.Qid{}, 0, fmt.Errorf("transact: %v", err)
+ return lib9p.Qid{}, 0, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RCreate:
@@ -396,7 +396,7 @@ func (c *Client) Read(tag uint16, fid uint32, offset uint64, count uint32) (data
tmsg := &lib9p.TRead{Tag: tag, Fid: fid, Offset: offset, Count: count}
rmsg, err := c.transact(tmsg)
if err != nil {
- return nil, fmt.Errorf("transact: %v", err)
+ return nil, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RRead:
@@ -411,7 +411,7 @@ func (c *Client) Write(tag uint16, fid uint32, offset uint64, count uint32, data
tmsg := &lib9p.TWrite{Tag: tag, Fid: fid, Offset: offset, Count: count, Data: data}
rmsg, err := c.transact(tmsg)
if err != nil {
- return 0, fmt.Errorf("transact: %v", err)
+ return 0, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RWrite:
@@ -426,7 +426,7 @@ func (c *Client) Clunk(tag uint16, fid uint32) error {
tmsg := &lib9p.TClunk{Tag: tag, Fid: fid}
rmsg, err := c.transact(tmsg)
if err != nil {
- return fmt.Errorf("transact: %v", err)
+ return fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RClunk:
@@ -441,7 +441,7 @@ func (c *Client) Remove(tag uint16, fid uint32) error {
tmsg := &lib9p.TRemove{Tag: tag, Fid: fid}
rmsg, err := c.transact(tmsg)
if err != nil {
- return fmt.Errorf("transact: %v", err)
+ return fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RRemove:
@@ -456,7 +456,7 @@ func (c *Client) Stat(tag uint16, fid uint32) (*lib9p.Stat, error) {
tmsg := &lib9p.TStat{Tag: tag, Fid: fid}
rmsg, err := c.transact(tmsg)
if err != nil {
- return nil, fmt.Errorf("transact: %v", err)
+ return nil, fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RStat:
@@ -471,7 +471,7 @@ func (c *Client) Wstat(tag uint16, fid uint32, stat *lib9p.Stat) error {
tmsg := &lib9p.TWstat{Tag: tag, Fid: fid, Stat: stat}
rmsg, err := c.transact(tmsg)
if err != nil {
- return fmt.Errorf("transact: %v", err)
+ return fmt.Errorf("transact: %w", err)
}
switch rmsg := rmsg.(type) {
case *lib9p.RWstat:
diff --git a/client/client_test.go b/client/client_test.go
@@ -38,47 +38,15 @@ func TestClientCancel(t *testing.T) {
wg.Wait()
}
-func setupClientAndServer(fs lib9p.FS) (*Client, context.CancelFunc) {
- cr, sw := io.Pipe()
- sr, cw := io.Pipe()
- s := lib9p.NewServer(fs)
- ctx, cancel := context.WithCancel(context.Background())
- go s.Serve(ctx, sr, sw)
- c := NewClient(ctx, 8*1024, "glenda", cr, cw)
- return c, cancel
-}
-
func TestDupTag(t *testing.T) {
- c, cancel := setupClientAndServer(testfs)
+ ctx, cancel := context.WithCancel(context.Background())
+ c, tmsgc, _ := newClientForTest(ctx, 1024, "glenda")
defer cancel()
- testfs.slow = true
- defer func() { testfs.slow = false }()
- _, _, err := c.Version(0, 8*1024, "9P2000")
- if err != nil {
- t.Fatal(err)
- }
- _, err = c.Attach(0, 0, lib9p.NOFID, "kenji", "")
- if err != nil {
- t.Fatal(err)
- }
- wname := []string{"a"}
- wqid, err := c.Walk(0, 0, 1, wname)
- if err != nil {
- t.Fatal(err)
- } else if len(wqid) != len(wname) {
- t.Fatal("file not found")
- }
- _, _, err = c.Open(0, 1, lib9p.OREAD)
- if err != nil {
- t.Fatal(err)
- }
- go func() {
- _, err = c.Read(0, 1, 0, 1024)
- }()
- <-testfs.waitc
- _, err = c.Stat(0, 1)
- if err == nil {
- t.Error("dup tag not reported")
+ go c.Version(0, 1024, "9P2000")
+ <-tmsgc
+ _, _, err := c.Version(0, 1024, "9P2000")
+ if !errors.Is(err, lib9p.ErrDupTag) {
+ t.Error("duplicate tag error not reported: err:", err)
}
}