-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make resolve now non block * Update resolver.go Co-authored-by: Geon Kim <geon0250@gmail.com> * rename lookupCloudmap --------- Co-authored-by: Geon Kim <geon0250@gmail.com>
- Loading branch information
1 parent
01012f2
commit fb354c5
Showing
3 changed files
with
123 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cloudmap | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/service/servicediscovery" | ||
"google.golang.org/grpc/grpclog" | ||
grpcresolver "google.golang.org/grpc/resolver" | ||
"google.golang.org/grpc/serviceconfig" | ||
"testing" | ||
"time" | ||
) | ||
|
||
type mockCC struct{} | ||
|
||
func (m mockCC) UpdateState(state grpcresolver.State) error { return nil } | ||
|
||
func (m mockCC) ReportError(err error) {} | ||
|
||
func (m mockCC) NewAddress(addresses []grpcresolver.Address) {} | ||
|
||
func (m mockCC) NewServiceConfig(serviceConfig string) {} | ||
|
||
func (m mockCC) ParseServiceConfig(serviceConfigJSON string) *serviceconfig.ParseResult { | ||
return nil | ||
} | ||
|
||
type mockDiscovery struct{} | ||
|
||
func (m mockDiscovery) DiscoverInstances(input *servicediscovery.DiscoverInstancesInput) (*servicediscovery.DiscoverInstancesOutput, error) { | ||
time.Sleep(1 * time.Second) | ||
fmt.Println("DiscoverInstances called") | ||
return &servicediscovery.DiscoverInstancesOutput{ | ||
Instances: make([]*servicediscovery.HttpInstanceSummary, 0), | ||
}, nil | ||
} | ||
|
||
func Test_resolver(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
r := &resolver{ | ||
logger: grpclog.Component("test"), | ||
|
||
cc: mockCC{}, | ||
sd: mockDiscovery{}, | ||
|
||
ctx: ctx, | ||
cancel: cancel, | ||
ticker: time.NewTicker(10 * time.Second), | ||
resolveCmd: make(chan struct{}, 1), | ||
} | ||
|
||
r.wg.Add(1) | ||
go r.watcher() | ||
|
||
timeout := time.After(100 * time.Millisecond) | ||
done := make(chan bool) | ||
go func() { | ||
for i := 0; i < 10; i++ { | ||
r.ResolveNow(grpcresolver.ResolveNowOptions{}) | ||
} | ||
done <- true | ||
}() | ||
select { | ||
case <-timeout: | ||
t.Error("timeout") | ||
case <-done: | ||
t.Log("done") | ||
} | ||
r.Close() | ||
} |