Skip to content
Snippets Groups Projects
Select Git revision
  • a4ee88cb55c14a09baa152dbfc47b9e57d3f7f3a
  • main default protected
  • drip-server-timing
  • compress-middleware
  • v2.11.0
  • v2.10.0
  • v2.9.2
  • v2.9.1
  • v2.9.0
  • v2.8.0
  • v2.7.0
  • v2.6.0
  • v2.5.6
  • v2.5.5
  • v2.5.4
  • v2.5.3
  • v2.5.2
  • v2.5.1
  • v2.5.0
  • v2.4.2
  • v2.4.1
  • v2.4.0
  • v2.3.0
  • v2.2.2
24 results

README.md

Blame
    • Will McCutchen's avatar
      20dd618a
      Support cmd/go-httpbin (:thumbsup:) and cmd/go_httpbin (:thumbsdown:) · 20dd618a
      Will McCutchen authored
      In #17, we switched to deploying httpbingo.org on Google App Engine. To
      meet their naming requirements, we had to rename cmd/go-httpbin to
      cmd/go_httpbin, but this broke any existing uses of, e.g.,
      
          go get github.com/mccutchen/go-httpbin/cmd/go-httpbin
      
      as suggested in the README and as used in various places (including my
      employer).
      
      Here's a dumb ass fix for that dumb ass problem; I'm not happy about it,
      but it seems to work.
      20dd618a
      History
      Support cmd/go-httpbin (:thumbsup:) and cmd/go_httpbin (:thumbsdown:)
      Will McCutchen authored
      In #17, we switched to deploying httpbingo.org on Google App Engine. To
      meet their naming requirements, we had to rename cmd/go-httpbin to
      cmd/go_httpbin, but this broke any existing uses of, e.g.,
      
          go get github.com/mccutchen/go-httpbin/cmd/go-httpbin
      
      as suggested in the README and as used in various places (including my
      employer).
      
      Here's a dumb ass fix for that dumb ass problem; I'm not happy about it,
      but it seems to work.
    event-bus_test.go 1.86 KiB
    package jobqueue
    
    import (
    	"sync"
    	"testing"
    	"time"
    )
    
    func TestSubscribeAndPublish(t *testing.T) {
    	eb := NewEventBus()
    
    	jobAddedCh := make(chan interface{}, 1)
    	eb.Subscribe(JobAdded, jobAddedCh)
    
    	jobData := "New Job Data"
    	eb.Publish(JobAdded, jobData)
    
    	select {
    	case receivedData := <-jobAddedCh:
    
    		rd := receivedData.(Event)
    
    		if rd.Data != jobData {
    			t.Errorf("Received data %v, want %v", receivedData, jobData)
    		}
    	case <-time.After(1 * time.Second):
    		t.Error("Timed out waiting for published event")
    	}
    }
    
    func TestUnsubscribe(t *testing.T) {
    	eb := NewEventBus()
    
    	jobAddedCh := make(chan interface{}, 1)
    	eb.Subscribe(JobAdded, jobAddedCh)
    	eb.Unsubscribe(JobAdded, jobAddedCh)
    
    	jobData := "New Job Data"
    	eb.Publish(JobAdded, jobData)
    
    	select {
    	case <-jobAddedCh:
    		t.Error("Received data after unsubscribing")
    	case <-time.After(1 * time.Second):
    		// Test passes if it times out (no data received)
    	}
    }
    
    func TestMultipleSubscribers(t *testing.T) {
    	eb := NewEventBus()
    
    	jobAddedCh1 := make(chan interface{}, 1)
    	jobAddedCh2 := make(chan interface{}, 1)
    	eb.Subscribe(JobAdded, jobAddedCh1)
    	eb.Subscribe(JobAdded, jobAddedCh2)
    
    	jobData := "New Job Data"
    	eb.Publish(JobAdded, jobData)
    
    	var wg sync.WaitGroup
    	wg.Add(2)
    
    	go func() {
    		defer wg.Done()
    		select {
    		case receivedData := <-jobAddedCh1:
    			rd := receivedData.(Event)
    			if rd.Data != jobData {
    				t.Errorf("Received data %v, want %v", receivedData, jobData)
    			}
    		case <-time.After(1 * time.Second):
    			t.Error("Timed out waiting for published event on channel 1")
    		}
    	}()
    
    	go func() {
    		defer wg.Done()
    		select {
    		case receivedData := <-jobAddedCh2:
    			rd := receivedData.(Event)
    
    			if rd.Data != jobData {
    				t.Errorf("Received data %v, want %v", receivedData, jobData)
    			}
    		case <-time.After(1 * time.Second):
    			t.Error("Timed out waiting for published event on channel 2")
    		}
    	}()
    
    	wg.Wait()
    }