11import { describe , it , expect } from '@jest/globals' ;
22
3- import { ApolloClientProvider } from '../src/provider' ;
4- import { ApolloClientOptions } from '../src/common' ;
3+ import { ApolloClientProvider , ApolloThirdPartClientProvider } from '../src/provider' ;
4+ import { ApolloClientOptions , ApolloThirdPartyHttpClientOptions } from '../src/common' ;
55
66const clientOptions : ApolloClientOptions = {
77 configServerUrl : 'http://106.54.227.205:8080' ,
@@ -78,33 +78,45 @@ describe('ApolloClient', () => {
7878 } , 900000 ) ;
7979
8080 it ( 'listenNamespace' , async ( ) => {
81- await apolloClient . listenNamespaces (
82- [
83- {
84- type : 'properties' ,
85- namespace : 'listenNamespace' ,
86- callback : ( config : any ) => {
87- if ( config . content === '1' ) {
88- apolloClient . clearListener ( 'listenNamespace' ) ;
89- expect ( ! ! config . content ) . toBe ( true ) ;
90- }
81+ const time = String ( Date . now ( ) ) ;
82+ const clientOptions : ApolloThirdPartyHttpClientOptions = {
83+ env : 'DEV' ,
84+ operator : 'apollo' ,
85+ appId : 'vodyani-apollo-config' ,
86+ portalServerUrl : 'http://106.54.227.205' ,
87+ token : 'fbf1302cd6b2417ebf4511555facbb2371a0fc40' ,
88+ } ;
89+ const httpClient = new ApolloThirdPartClientProvider ( clientOptions ) ;
90+
91+ await Promise . all ( [
92+ apolloClient . listenNamespaces (
93+ [
94+ {
95+ type : 'properties' ,
96+ namespace : 'listenNamespace' ,
97+ callback : ( config : any ) => {
98+ if ( config . content === time ) {
99+ apolloClient . clearListener ( 'listenNamespace' ) ;
100+ expect ( ! ! config . content ) . toBe ( true ) ;
101+ }
102+ } ,
91103 } ,
92- } ,
93- {
94- type : 'json ' ,
95- namespace : 'listenNamespace3' ,
96- callback : ( config : any ) => {
97- if ( config . content === '3' ) {
98- apolloClient . clearListener ( 'listenNamespace3' ) ;
99- expect ( ! ! config . content ) . toBe ( true ) ;
100- }
104+ {
105+ type : 'json' ,
106+ namespace : 'listenNamespace3 ' ,
107+ callback : ( config : any ) => {
108+ if ( config . content === time ) {
109+ apolloClient . clearListener ( 'listenNamespace3' ) ;
110+ expect ( ! ! config . content ) . toBe ( true ) ;
111+ }
112+ } ,
101113 } ,
102- } ,
103- ] ,
104- ) ;
105-
106- // 增加修改 + 发布的流程,触发名称更新
107- } , 900000 ) ;
114+ ] ,
115+ ) ,
116+ httpClient . saveConfig ( 'listenNamespace' , 'properties' , time ) ,
117+ httpClient . saveConfig ( 'listenNamespace3' , 'json' , JSON . stringify ( { content : time } ) ) ,
118+ ] ) ;
119+ } ) ;
108120
109121 it ( 'listenNamespace Namespace duplication' , async ( ) => {
110122 try {
@@ -123,6 +135,8 @@ describe('ApolloClient', () => {
123135 const clientOptions : ApolloClientOptions = {
124136 configServerUrl : 'http://106.54.227.205:8080' ,
125137 appId : 'vodyani-apollo-config' ,
138+ retry : 1 ,
139+ delay : 100 ,
126140 } ;
127141
128142 const apolloClient = new ApolloClientProvider ( clientOptions ) ;
0 commit comments