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.

https://medium.com/wttj-tech/dealing-with-idempotence-in-elixir-projects-with-the-ecto-sandbox-benefits-and-points-to-consider-e16039bb2c21

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.External module, with functions to work with typespecs in modules outside of your control.

    • fetch_spec to build a TypeCheck type from any function that has a @spec.
    • fetch_type to build a TypeCheck type from any @type.
    • enforce_spec! to wrap a call to any function that has a @spec with a runtime type-check on the input parameters and return value.
    • apply and apply! 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_list type 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.

https://podcast.thinkingelixir.com/102

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

Elixir metrics and StatsD

I wrote a new article in the “Elixir Telemetry” series.

Read it here:

https://blog.miguelcoba.com/elixir-metrics-and-statsd

Petal Components - ElixirCasts

In this episode, we’ll learn how to use Petal Components in a Phoenix application.

https://elixircasts.io/petal-components

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 format external 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 as mix format works at the file-level.

    • Allow mix format external formatter to be disabled.
      1. Preferences
      2. Editor > Code Style > Elixir
      3. Click the mix format tab
      4. Expand the General group
      5. Uncheck “Format files with mix format“.
  • Support Elixir 1.13.0 in debugger.

Bug Fixes

  • Look above CallDefinitionImpl for Type scope processing It should go up to the ModuleImpl to find the TypeDefinitionImpl.
  • Have Credo Global Inspection use standard Mix.commandLine used 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
    • Mirror TypeDefinitionImpls to types in decompiled source. Allow TypeDefinitionImpl.getNavigation to go to decompiled types.
  • 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 from equals to == when fixing the deprecation warnings, which made the Project SDK selection only be HIDDEN where it needed to be SHOWN.
  • Catch StackOverflowError in find_usages.Provider.getType().
  • Element descriptions for CallDefinitionImpl
  • Highlight CallDefinitionImpl references as predefined if resolved CallDefinitionImpl is in Kernel or Kernel.SpecialForms. Fixes highlighting def and 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.getBuilder ModuleBuilders as potential project builders, so it looked like Elixir New Project support disappeared. Fix this by implementing the newProjectWizard.language extension that was added to control the Language switching in the new New Project dialog.
  • Remove references to ElementClassHint in BeamFileImpl that only work in IntelliJ. ElementClassHint is part of the processDeclaration system used in Java and so was in the code because BeamFileImpl was original based on ClassFileImpl, 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 env from the Configuration was dropped because a local env was created to set MIX_ENV true.

Installation Instructions

🎉 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.

https://paraxial.io/blog/beta-announcement

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.

https://podcast.thinkingelixir.com/101

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.

More on: https://bartoszgorka.com/til-temporary-data-folder

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

[Poll] What is the oldest version of Elixir you use to run Wallaby?

Link to poll: https://twitter.com/elixir_wallaby/status/1531356768332353543?s=20

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 đŸ”„

  1. Gustavo Oliveira - Use TDD step by step with live view
  2. 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

Previous page Next page