Dealing with idempotence in Elixir projects with the Ecto sandbox: benefits and points to consider
As a QA team, we quickly faced a challenge encountered by all teams when they build their test automation solution: successfully controlling our environment and restoring our initial dataset in order to respect the idempotence of executions. To manage this, we chose to activate the Ecto sandbox for our Cypress tests. In this article, we will focus on the benefits of this sandbox as well as the things to look out for from a QA perspective.
wxErlang Hello World
In this post I explore wxErlang, a binding for wxWidgets. https://hidnasio.github.io/elixir/wxerlang/2022/06/08/wx-erlang-hello-world.html
TypeCheck v0.12.0 released
Version 0.12.0 of TypeCheck has been released! đ
Additions:
Per-dependency configuration
The default options used are now fetched from the application configuration.
This means that you can configure a default for your app as well as for each of your dependencies(!) by adding config :app_name, :type_check [âŠ] to your configuration file(s).
(This configuration can then further be overridden per module, which was already possible in earlier versions.)
Building types and checks for external functions
If you want to use types from modules outside of your control, until now you had to manually recreate them. Now, the TypeCheck.External module allows fetching the ânormalâ types and specs from a compiled module. Specifically:
-
TypeCheck.Externalmodule, with functions to work with typespecs in modules outside of your control.-
fetch_specto build a TypeCheck type from any function that has a@spec. -
fetch_typeto build a TypeCheck type from any@type. -
enforce_spec!to wrap a call to any function that has a@specwith a runtime type-check on the input parameters and return value. -
applyandapply!to wrap a call to any function with the function spec type that you give it.
-
iex> TypeCheck.External.enforce_spec!(Kernel.abs(-13))
13
iex> TypeCheck.External.enforce_spec!(Kernel.abs("hi"))
** (TypeCheck.TypeError) At lib/type_check/external.ex:175:
`"hi"` is not a number.
This functionality is still very new, so we consider it to be a little experimental. In the near future, it might be integrated further with the rest of the library. For instance, we might add syntactic sugar to make âtype overridesâ easier.
I want to take this opportunity to thank @orsinium greatly. Both the idea and the implementation of this functionality is his work! :star_struck:
Defstruct!
TypeCheck.Defstruct.defstruct!, a way to combine defstruct, @enforce_keys and the creation of the structâs type, reducing boilerplate and the possibility of mistakes. (c.f. #118 )
Example:
defmodule User do
use TypeCheck
use TypeCheck.Defstruct
defstruct!(
name: "Guest" :: String.t(),
age: _ :: non_neg_integer()
)
end
is syntactic sugar for:
defmodule User do
use TypeCheck
use TypeCheck.Defstruct
@type! t() :: %User{
name: String.t(),
age: non_neg_integer()
}
@enforce_keys [:age]
defstruct [:age, name: "Guest"]
end
Fixes:
- Long-standing issue where Dialyzer would sometimes complain in apps using TypeCheck is resolved. (c.f. #95)
-
Creation of the new
maybe_nonempty_listtype will no longer get stuck in an infinite loop on creation. (c.f. #120)
This new release is just in time for ElixirConf.EU where I will be speaking about TypeCheck. I look forward to see a lot of you there (live or virtually)!
There will also be stickers! đ
As always, you can find TypeCheck on Hex.PM, on GitHub and on the Elixir forum.
ThinkingElixir 102: Machine Learning in Elixir with Sean Moriarity
In episode 102 of Thinking Elixir, Sean Moriarity, the author of Genetic Algorithms in Elixir, lays out Machine Learning in the Elixir space. We talk about where it is today and where itâs going in the future. Sean talks more about his book, how that led to working with JosĂ© Valim which then led to the creation of Nx. He fills us in on recent ML events with Google and Facebook and shows us how Elixir fits into the bigger picture. Itâs a fast developing area and Sean helps us follow the important points even if we arenât doing ML ourselves⊠because our teams may still need it.
Elixir Code Smells with Lucas Vegi and Marco Tulio
In this episode we talk with Lucas Vegi, professor at UFV and PhD student at UFMG, and Marco Tulio Valente, professor at UFMG, about the paper entitled Code Smells in Elixir: Early Results from a Grey Literature Review
English subtitles available
https://www.elixiremfoco.com/episode?id=lucas-vegi-e-marco-tulio
Is the test LiveView immutable or not?
Someone from my Testing LiveView course recently asked me about the immutability of the view we get from live/2 in LiveView tests. Itâs not the first time someoneâs asked me that question, so I wanted to try to clarify things a bit.
I hope this helps others too!
https://www.germanvelasco.com/blog/is-the-test-liveview-immutable-or-not
Petal Components - ElixirCasts
In this episode, weâll learn how to use Petal Components in a Phoenix application.
The Comprehensive Guide to Elixir's List Comprehension
List comprehensions are one of my favorite features of Elixir and I am excited to finally be writing about them! In the article I go over every single feature and option of the comprehension, how to use them, and how they compare to Enum and recursive functions.
https://www.mitchellhanberg.com/the-comprehensive-guide-to-elixirs-for-comprehension/
IntelliJ Elixir v13.1.0
Changelog
v13.1.0
Enhancements
-
New Project > Language > Elixir includes all mix options
-
âapp -
âmodule -
âsup -
âumbrella
-
-
Add
mix formatexternal formatter. Requires project or module SDK be set in order to run. If the SDK is not available, only the internal formatter will be used. The internal formatter is still used for file subsection formatting and new line indenting asmix formatworks at the file-level.-
Allow
mix formatexternal formatter to be disabled.- Preferences
- Editor > Code Style > Elixir
-
Click the
mix formattab - Expand the General group
-
Uncheck âFormat files with
mix formatâ.
-
Allow
-
Support Elixir 1.13.0 in debugger.
Bug Fixes
-
Look above
CallDefinitionImplforTypescope processing It should go up to theModuleImplto find theTypeDefinitionImpl. -
Have Credo Global Inspection use standard
Mix.commandLineused for Run Configurations.- Allow environment variables to be set similar to Run Configurations for projects that require environment variables to be set for Mix tasks due to checks in their config.
- No longer support Include Explanations as it takes too long to run.
- Remove annotator until it can be re-implemented in performant manner using corrected environment and SDK from Global Inspection.
-
Fix Find Usages that resolve to compiled types.
-
Add element description for
TypeDefinitionImpl-
Node Text is
@<module_attribte> <name>(<parameters>) :: ⊠-
Long Name and Short Name are just the
name -
Type is
type
-
Node Text is
-
Mirror
TypeDefinitionImplsto types in decompiled source. AllowTypeDefinitionImpl.getNavigationto go to decompiled types.
-
Add element description for
- Allow types with atom keyword names to be highlight even though they are invalid names.
-
Restore Project configuration for Small IDEs.
I dropped an
!when converting fromequalsto==when fixing the deprecation warnings, which made the Project SDK selection only be HIDDEN where it needed to be SHOWN. -
Catch
StackOverflowErrorinfind_usages.Provider.getType(). -
Element descriptions for
CallDefinitionImpl -
Highlight
CallDefinitionImplreferences as predefined if resolvedCallDefinitionImplis inKernelorKernel.SpecialForms. Fixes highlightingdefand other defined when using SDKs without source like Homebrew after the delayed-decompilation fixes from 12.2.1. Now source-less (Homebrew) and SDKs with sources (ASDF) will both be able to highlight predefineds. -
No longer record the SDK name as an attribute of the Facet configuration, as it didnât write back changes.
- Instead detect the Elixir SDK by finding any of the libraries that have an Elixir SDK name in the module. (The Elixir SDK was already being added as a library to allow indexing the SDK.)
- Clear out any existing Elixir SDKs listed as module libraries before setting a new SDK. This eliminates the duplicates that happened before. (It turns out the JetBrains API doesnât prevent duplicates. Oopsie.) It also ensures that no SDK is recorded if the SDK is deselected in the UI, which wouldnât happen before.
-
In IntelliJ 2022, the New Project dialog changed and it no longer automatically listed
ModuleType.getBuilderModuleBuilders as potential project builders, so it looked like Elixir New Project support disappeared. Fix this by implementing thenewProjectWizard.languageextension that was added to control the Language switching in the new New Project dialog. -
Remove references to
ElementClassHintin BeamFileImpl that only work in IntelliJ.ElementClassHintis part of theprocessDeclarationsystem used in Java and so was in the code becauseBeamFileImplwas original based onClassFileImpl, but since the Elixir resolvers donât use the hint system at all, it can just be removed. -
Fix environment not being passed to debug runs of ESpec and ExUnit Run Configurations.
The
envfrom theConfigurationwas dropped because a localenvwas created to setMIX_ENVtrue.
đ Announcing the Paraxial.io Beta Launch!
Paraxial.io protects your Elixir/Phoenix application from bots attempting automated logins, scraping, and disruption of service. Today we are happy to announce the beta program is open to new users!
To sign up, email support@paraxial.io with a brief description of your website. The beta is open to anyone with an Elixir/Phoenix application, from a personal project to larger corporate site.
ThinkingElixir 101: Replicating SQLite using Litestream with Ben Johnson
In episode 101 of Thinking Elixir, Ben Johnson explains his project Litestream.io, an OpenSource tool that replicates SQLite databases to remote servers and to backup locations like S3 for durability. We talk about how moving data out to the user creates true edge applications. We discuss what types of problems this helps solve, the architectures that become possible, and how a globally distributed Phoenix application could use this. He shares how Fly.io acquired the project and brought him on full-time to continue his work on it. Fascinating discussion that challenges many of the assumptions about how weâve been building âwebâ systems for years.
Algebraic Data Types in Elixir
Discover the ins and outs of ADTs and their benefits for your Elixir app. https://blog.appsignal.com/2022/05/31/algebraic-data-types-in-elixir.html
TIL: Temporary data folder
The temporary directory for data storage is often used. However, /tmp dir is not always a good solution. Depending on the configuration, it can be represented differently. Check how you can fix it with simple modification.
ExMarcel: A Library for MIME type detection based on magic numbers
Marcel attempts to choose the most appropriate content type for a given file by looking at the binary data, the filename, and any declared type. This package is a port of Railsâs Marcel library. https://github.com/chaskiq/ex-marcel
Boost your test coverage with Elixir
In this article, I will help you build the appropriate tooling to track and measure your test coverage, and hopefully improve it.
https://www.christianblavier.com/boost-your-test-coverage-with-elixir/
Elixir Meetup #6 hosted by Curiosum
Elixir Meetup #6 on June 8, 2022 at 18 CET
Where? đ ONLINE & FREE
Register đđ https://curiosum.com/meetups/elixir
đ„ Speakers đ„
- Gustavo Oliveira - Use TDD step by step with live view
- Adolfo Neto - Learning Erlang and Elixir through exercises and the advent of code
Simple Dependency Injection in ExUnit
Smart testing strategies for Elixir with Dependency Injection design pattern: https://k.lelonek.me/simple-di-in-elixir
Conference report: Code BEAM, Stockholm 2022
I wrote up my experience at Code BEAM in Stockholm this year.
I really enjoyed it :) https://underjord.io/code-beam-sto-2022.html
