@@ -45,7 +45,7 @@ class EngineRunningTest extends Specification {
4545 states == [true , false ]
4646 }
4747
48- def " engine running state is observed with async datafetcher" () {
48+ def " engine running state is observed with one async datafetcher" () {
4949 given :
5050 def sdl = '''
5151
@@ -80,11 +80,62 @@ class EngineRunningTest extends Specification {
8080 cf. complete(" world" )
8181
8282 then :
83- // TODO: why is that so much back and forth between true and false?
84- states == [true , false , true , false , true , false , true , false ]
83+ states == [true , false ]
8584 er. get(). data == [hello : " world" ]
8685
8786 }
8887
88+ def " engine running state is observed with two async datafetcher" () {
89+ given :
90+ def sdl = '''
91+
92+ type Query {
93+ hello: String
94+ hello2: String
95+ }
96+ '''
97+ CompletableFuture cf1 = new CompletableFuture ();
98+ CompletableFuture cf2 = new CompletableFuture ();
99+ def df = { env ->
100+ return cf1;
101+ } as DataFetcher
102+ def df2 = { env ->
103+ return cf2
104+ } as DataFetcher
105+
106+ def fetchers = [" Query" : [" hello" : df, " hello2" : df2]]
107+ def schema = TestUtil . schema(sdl, fetchers)
108+ def graphQL = GraphQL . newGraphQL(schema). build()
109+
110+ def query = " { hello hello2 }"
111+ def ei = newExecutionInput(query). build()
112+
113+ List<Boolean > states = new CopyOnWriteArrayList<> ();
114+ ei. getGraphQLContext(). put(ENGINE_RUNNING_OBSERVER_KEY , {
115+ ExecutionId executionId, GraphQLContext context, boolean running ->
116+ states. add(running)
117+ } as EngineRunningObserver );
118+
119+ when :
120+ def er = graphQL. executeAsync(ei)
121+ then :
122+ states == [true , false ]
123+
124+ when :
125+ states. clear();
126+ cf1. complete(" world" )
127+
128+ then :
129+ states == [true , false ]
130+
131+ when :
132+ states. clear();
133+ cf2. complete(" world2" )
134+
135+ then :
136+ states == [true , false ]
137+ er. get(). data == [hello : " world" , hello2 : " world2" ]
138+ }
139+
89140
90141}
0 commit comments