The Rust ecosystem has grown exponentially, especially in areas where concurrency and safety are critical. However, testing stateful and concurrent APIs remains one of the biggest challenges for development teams. Large language models (LLMs) can generate executable tests, but often these tests are shallow, violate preconditions, or reduce concurrency to accidental sequential traces. On the other hand, model-based systematic testing techniques offer precise semantic control but require a considerable amount of handwritten code to turn abstract scenarios into executable tests. This article explores a hybrid approach that combines Petri nets with LLMs to generate deep, semantically valid tests, and how companies like Q2BSTUDIO integrate these methodologies into custom software development.
Colored Petri nets allow explicit modeling of resources, lifecycle states, and causal dependencies of an API. Each resource is represented as a colored token that transitions between places (states) through transitions (actions). This model captures not only deep legal states but also near-legal or partial-order concurrent scenarios. From these nets, it is possible to derive a set of abstract scenarios that serve as an intermediate representation for code synthesis via LLM. The process includes a local-faithfulness contract and a structural repair loop that preserves the model's intent during concretization. Moreover, Petri-guided schedule shaping prioritizes high-conflict concurrency skeletons for systematic exploration.
The resulting testing architecture incorporates a layered semantic oracle that distinguishes synthesis failures from violations of the target API's expected behavior. This allows developers to focus on real API errors instead of debugging test generation issues. For companies developing applications in Rust —whether for embedded systems, cloud services, or financial platforms— this approach means significant time savings and improved concurrent test coverage.
The colored Petri net (CPN) model is especially suitable for Rust due to its ownership and lifetime system. Each token can represent a unique resource with a specific life state, and transitions model operations that transfer or transform those resources. For example, a connection management API can be represented with tokens traveling from 'disconnected' to 'connected', 'authenticated', and eventually 'closed'. Concurrent transitions capture operations such as opening multiple connections or closing one while another authenticates. This modeling enables the generation of test scenarios that cover both happy paths and edge conditions, such as using a resource after its release.
Concretization via LLM starts from these abstract scenarios. The model receives a structured description of the Petri net and expected behavior, and generates Rust code that implements the test. The local-faithfulness contract ensures each test step respects the model's preconditions. If the LLM introduces errors, the structural repair loop identifies inconsistencies and requests a new generation. This approach drastically reduces the development time for complex tests, which would otherwise require hours of manual coding.
In the business domain, Q2BSTUDIO has applied this methodology in several high-profile projects. For instance, in a concurrent message queue system developed in Rust for a fintech, we used Petri nets to model the states of each message (pending, processing, completed, failed) and the transitions between them. From that model, we automatically generated hundreds of tests that uncovered several deadlocks and race conditions that traditional unit tests missed. Integration with our Azure cloud infrastructure allowed these tests to run in parallel, reducing feedback time to minutes.
At Q2BSTUDIO, we understand that software quality is non-negotiable. That is why when developing custom software, we integrate advanced testing methodologies. Our team combines formal techniques such as Petri nets with artificial intelligence to automate test generation. This is particularly relevant for projects requiring high concurrency, such as trading platforms, IoT systems, or microservices deployed on cloud AWS and Azure. The ability to model resource flow and states allows us to anticipate concurrency issues before they reach production.
Cybersecurity is another fundamental pillar. Tests generated with Petri nets can detect race conditions and security violations that would otherwise go unnoticed. At Q2BSTUDIO we offer cybersecurity and pentesting services, where we apply these same principles to audit Rust applications and other languages. We also integrate business intelligence with Power BI to visualize quality metrics and test coverage, and we develop AI agents that assist in creating and maintaining test suites.
The integration of AI agents into the testing cycle is another area where Q2BSTUDIO makes a difference. These agents can interpret Petri net models, generate initial test code, and refine tests based on execution results. Combined with cloud infrastructure, we can scale massive concurrent test execution without incurring prohibitive costs. Automating testing processes through intelligent agents is a service we offer as part of our digital transformation solutions.
The future of software testing lies in the symbiosis between formal models and machine learning. Petri nets provide a solid mathematical foundation, while LLMs bring the flexibility needed to generate executable code quickly. At Q2BSTUDIO, we are committed to this vision. Our engineering team combines expertise in automata theory, concurrent languages, and enterprise software development to deliver robust solutions. Whether you need to develop an application from scratch, migrate to the cloud, or audit your system's security, we have the tools and knowledge to do it with excellence.
To learn more about how we can help you implement advanced testing strategies in your projects, visit our artificial intelligence page or contact us directly. At Q2BSTUDIO, we turn technical complexity into competitive advantages.




