...

Source file src/github.com/gomodule/redigo/redis/pool17_test.go

Documentation: github.com/gomodule/redigo/redis

     1  // Copyright 2018 Gary Burd
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  // +build go1.7
    16  
    17  package redis_test
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/gomodule/redigo/redis"
    24  )
    25  
    26  func TestWaitPoolGetContext(t *testing.T) {
    27  	d := poolDialer{t: t}
    28  	p := &redis.Pool{
    29  		MaxIdle:   1,
    30  		MaxActive: 1,
    31  		Dial:      d.dial,
    32  		Wait:      true,
    33  	}
    34  	defer p.Close()
    35  	c, err := p.GetContext(context.Background())
    36  	if err != nil {
    37  		t.Fatalf("GetContext returned %v", err)
    38  	}
    39  	defer c.Close()
    40  }
    41  
    42  func TestWaitPoolGetAfterClose(t *testing.T) {
    43  	d := poolDialer{t: t}
    44  	p := &redis.Pool{
    45  		MaxIdle:   1,
    46  		MaxActive: 1,
    47  		Dial:      d.dial,
    48  		Wait:      true,
    49  	}
    50  	p.Close()
    51  	_, err := p.GetContext(context.Background())
    52  	if err == nil {
    53  		t.Fatal("expected error")
    54  	}
    55  }
    56  
    57  func TestWaitPoolGetCanceledContext(t *testing.T) {
    58  	d := poolDialer{t: t}
    59  	p := &redis.Pool{
    60  		MaxIdle:   1,
    61  		MaxActive: 1,
    62  		Dial:      d.dial,
    63  		Wait:      true,
    64  	}
    65  	defer p.Close()
    66  	ctx, f := context.WithCancel(context.Background())
    67  	f()
    68  	c := p.Get()
    69  	defer c.Close()
    70  	_, err := p.GetContext(ctx)
    71  	if err != context.Canceled {
    72  		t.Fatalf("got error %v, want %v", err, context.Canceled)
    73  	}
    74  }
    75  

View as plain text