Test runners - Update result with runners
No Python support
We have not implemented this SDK function in Python yet.
The updateTestResultWithRunners()
function allows you to update an existing test result with additional case output data. This function is complementary with getTestRunners()
and submitTestRunners()
.
Use cases
- Chunked uploads for large datasets exceeding API gateway limits (e.g., 10 MB for AWS)
- Incremental addition of test case results for long-running processes
- Targeted updates to specific test cases within a larger result set
Parallelization Example
typescript
import {init ,Pipeline ,PipelineRunTestCaseTuple ,getTestRunners ,submitTestRunners ,updateTestResultWithRunners ,} from '@gentrace/core';functionexampleResponse (inputs : any) {return 'This is a generated response from the AI';}// utility function to enable parallelismexport constenableParallelism = async <T ,U >(items :T [],callbackFn : (t :T ) =>Promise <U >,{parallelThreads = 10 }: {parallelThreads ?: number } = {},) => {constresults =Array <U >(items .length );constiterator =items .entries ();constdoAction = async (iterator :IterableIterator <[number,T ]>) => {for (const [index ,item ] ofiterator ) {results [index ] = awaitcallbackFn (item );}};constworkers =Array (parallelThreads ).fill (iterator ).map (doAction );awaitPromise .allSettled (workers );returnresults ;};async functionmain () {init ({apiKey :process .env .GENTRACE_API_KEY ?? '',});constPIPELINE_SLUG = 'guess-the-year';// get the existing pipeline (if already exists)constpipelineBySlug = newPipeline ({slug :PIPELINE_SLUG ,});// example pipeline by IDconstpipelineById = newPipeline ({id : 'c10408c7-abde-5c19-b339-e8b1087c9b64',});constpipeline =pipelineBySlug ;constexampleHandler = async ([runner ,testCase ,]:PipelineRunTestCaseTuple ) => {awaitrunner .measure ((inputs : any) => {return {example :exampleResponse (inputs ),};},[testCase .inputs ],);};constpipelineRunTestCases = awaitgetTestRunners (pipeline );// Create an initial empty test resultconstinitialResult = awaitsubmitTestRunners (pipeline , []);constresultId =initialResult .id ;// Process test cases in batches of 10, mimicking behavior in a distributed datacenter.// This approach allows for efficient processing of large datasets by breaking them into// manageable chunks, similar to how distributed systems handle data processing across// multiple nodesconstbatchSize = 10;for (leti = 0;i <pipelineRunTestCases .length ;i +=batchSize ) {constbatch =pipelineRunTestCases .slice (i ,i +batchSize );awaitenableParallelism (batch ,exampleHandler , {parallelThreads : 5,});// Update the test result with the processed batchawaitupdateTestResultWithRunners (resultId ,batch );console .log (`Updated result with batch ${i /batchSize + 1}`);}console .log (`Finished updating result ${resultId }`);}main ();